0

I have just created a form with sending email but my module is not working on front end its going to 404 so i am unable to test if my form is working and sending email

My Config.xml file in app > code > community > Optfirst > ReviewMyCompany > etc

<frontend>
<routers>
  <reviews>
    <use>standard</use>
      <args>
        <module>OptFirst_ReviewMyCompany</module>
        <frontName>reviews</frontName>
      </args>
  </reviews>
    <emailus>
        <use>standard</use>
            <args>
                <module>OptFirst_ReviewMyCompany</module>
                <frontName>emailus</frontName>
            </args>
    </emailus>
</routers>
    <layout>
      <updates>
        <reviews>
          <file>reviews.xml</file>
        </reviews>
      </updates>
    </layout>

And Here is my EmailusController.php file:

      <?php

      class OptFirst_ReviewMyCompany_EmailusController extends Mage_Core_Controller_Front_Action
    {

      public function sendemailAction()
    {
    //Fetch submited params
    $params = $this->getRequest()->getParams();

    $mail = new Zend_Mail();
    $mail->setBodyText($params['comment']);
    $mail->setFrom($params['email'], $params['name']);
    $mail->addTo('shoaibswl123@gmail.com', 'Some Recipient');
    $mail->setSubject('Test  Module for Magento');
    try {
        $mail->send();
    }        
    catch(Exception $ex) {
        Mage::getSingleton('core/session')->addError('Unable to send email. Sample of a custom notification error from Contact.');

    }

    //Redirect back to index action of (this) controller
    $this->_redirect('optfirst_reviewmycompany/');
}
  }

and my form action on frontend is this:

action="<?php echo $this->getUrl('optfirst_reviewmycompany/') ?>emailus/sendemail" method="post">

But its not sending email it just take to 404 page when i submit the form

0

I assume that you are working on a development box:

First of all, you have 2 different routers defined for your extension... while this COULD be possible, I don't think that you are doing it as you intend. My recommendation: Pick One (and it should be the same as the rest of the short tags for your extension).

Second, your action is incorrect, and should be:

action="<?php echo $this->getUrl('reviews/emailus/sendemail') ?>" method="post">

You build the URL based on 3 parts:

  1. The module router tag (in your case EITHER reviews or emailus)
  2. The the lowercase subcomponent name of the controller (in your case emailus)
  3. The name of the action (excluding the Action() part)

To clarify, let me give a different example from default Magento:

Mage_Paygate_Authorizenet_PaymentController::cancelAction()

If you dig into app/code/core/Mage/Paygate/etc/config.xml you will see that the module router name is paygate, so replace the first part of the controller class like this:

paygate/Authorizenet_PaymentController

Now for part #2... Controller is stripped out and the rest of the last half is converted FROM camelcase (only modify the first letter for each "word" separated by _). So now you end up with:

paygate/authorizenet_payment

By default the controller will load the index action, and is the same as:

paygate/authorizenet_payment/index

But we don't want the index action (it doesn't even exist), we want the cancel action:

paygate/authorizenet_payment/cancel

Now we have the full URL in the format: MODULE/CONTROLLER/ACTION.

In order to test that you are actually reaching the correct controller action, I recommend putting this near the top of the function (temporarily of course):

public function sendemailAction()
{
    //Fetch submited params
    $params = $this->getRequest()->getParams();

    die('<pre>' . print_r($params, true));  // <---- THIS HERE TO TEST
  • thats fixed now the error is :Unable to send email. Sample of a custom notification error from – Xabby Nov 30 '16 at 10:54
  • That error is coming straight from your code, its the exception that you caught from $mail->send(). Use something like die($ex->__toString()); instead of your current error handler to see the ACTUAL exception. – Phil M Nov 30 '16 at 16:24

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.