1

I am having difficulty making my custom email form receive emails. My success message does not show when the submit button is clicked. I also am getting a Confirm Form Resubmission error when refreshing the page after clicking submit. I am not sure what I am missing to make it work.

Any help would be much appreciate. Here is my php controller function:

public function sendemailAction()
{
    $email = $this->getRequest()->get('email');
    $name = $this->getRequest()->get('name');
    $comment = $this->getRequest()->get('comment');
    $contact = $this->getRequest()->get('support_contact');
    $session = $this->getSession();

    $mail = new Zend_Mail();
    $mail->setBodyText($comment);
    $mail->setFrom($email, $name);

    $mail->setSubject('Vendor Support');

    $mail->addTo($contact . '@example.com');

    try {
        $mail->send();
        $session->addSuccess($this->__('Thank You! We will get in touch with you as soon as possible.'));
    } catch (Exception $ex) {
        Mage::getSingleton('udropship/session')->addError('Unable to send email.');

    }

    $this->_redirect('udropship/vendor');
}

My layout.xml file:

<udropship_vendor_support>
    <update handle="udropship_vendor" />

    <reference name="content">
        <block name="vendor.support" type="itemique_dropship/template" template="unirgy/dropship/vendor/support.phtml"/>
    </reference>
</udropship_vendor_support>

And my support phtml file:

<form id="support-form" class="standalone-form" action="<?php echo $this->getUrl('udropship/vendor/support'); ?>" method="post" enctype="application/x-www-form-urlencoded">

<h1><?php echo $helper->__('How can we help?'); ?></h1>

<fieldset class="form-content">
    <div class="form-row">
        <label for="support_contact">Contact department <span class="required">*</span></label>
        <select id="support_contact" class="select" name="support_contact" required>
            <option value="" disabled selected>--Please Select--</option>
            <option value="billing">Billing Enquiries</option>
            <option value="content">Content Support</option>
            <option value="tech">Technical Support</option>
            <option value="contact">Customer Service</option>
        </select>
    </div>

    <div class="form-row">
        <label for="comment">Your issue? <span class="required">*</span></label>
        <textarea class="textarea" name="comment" id="comment" required></textarea>
    </div>
</fieldset>

<div class="buttons-set">
    <p class="required">* Required Fields</p>
    <button type="submit" class="btn primary" name="send">
        <span><?php echo $helper->__('Submit') ?></span>
    </button>
</div>

  • 1
    Does your form action not need to be - action="<?php echo $this->getUrl('udropship/vendor/sendemail'); ?>"? – Muzza Aug 3 '15 at 10:42
  • I don't have a sendemail url though. Sorry, what do you mean exactly? Slightly confused. – Allan Fitzpatrick Aug 3 '15 at 11:47
  • You have set your controller action as 'sendemailAction', therefore you need to submit to this. Currently your form is submitting to the 'supportAction' as you are telling it to here - action="<?php echo $this->getUrl('udropship/vendor/support'); ?>" – Muzza Aug 3 '15 at 12:24
  • No problem! I have added the above solution as an answer so please accept if this fixed your issue. – Muzza Aug 3 '15 at 16:05
2

It seems like your Form action is generating the wrong Magento controller URL.

Please update your phtml form action to:

<?php echo $this->getUrl('udropship/vendor/support'); ?>

This will then create the correct URL for you to post to.

1

Do you have the smtp settings in php.ini, or are you using Magento's settings? If you're using Magento settings, you'll need to make them available to PHP. Here's what Magento does in core/email_template, send method:

ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));

Cheers

  • Hi Adrian, I am using Magento's settings. Have fixed it partially. From my attempts at debugging the mail sends now but it doesn't arrive in my mailbox. – Allan Fitzpatrick Aug 3 '15 at 15:52
  • How do you know it actually sends? Maybe you have some aggressive spam filters; try using a mailinator.com address to test. – Adi Aug 3 '15 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.