I created form but I don't know how to add a controller to send mail with these field

     public function saveAction()
        //on recuperes les données envoyées en POST
        $orderid = ''.$this->getRequest()->getPost('orderid');
        $reason = ''.$this->getRequest()->getPost('reason');
          //on verifie que les champs ne sont pas vide
        if(isset($orderid)&&($orderid!='') && isset($reason)&&($reason!=''))
          //on cree notre objet et on l'enregistre en base
          $contact = Mage::getModel('test/test');
          $contact->setData('orderid', $orderid);
          $contact->setData('reason', $reason);

        $body ='Hi admin, '.$orderid. 'reason'.$reason;
    $mail = Mage::getModel('core/email');
    $mail->setToEmail('[email protected]');

    $mail->setSubject('Not Support Pincode');
    $mail->setType('html');// You can use 'html' or 'text'

    try {
    //Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
    catch (Exception $e) {
    //Mage::getSingleton('core/session')->addError('Unable to send.');
   // $this->_redirect('');
       //on redirige l’utilisateur vers la méthode index du controller indexController
       //de notre module <strong>test</strong>


<form action="<?php echo Mage::getUrl('test/index/save') ?>" method="post">

    <h1><?php echo "Order Cancel Request Form"; ?></h1>

    <!-- Get Customer Current Order ID -->    
       <div class="cancel-order-id"> 
           <label for="orderid"> Your Order Id : </label> <input id ="orderid" type="text" value = "<?php echo Mage::app()->getRequest()->getParam('ref');?>" readonly> 
    <!-- Get Customer Current Order ID -->

    <!-- Reason -->
    <div class="cancel-order-reason"> 
        <label for="reason">Reason Of Cancel : </label>
        <textarea id="reason" rows="4" cols="50">  </textarea>

    <input type="button" value="submit">

    <!-- Reason -->

  • Add an action method that will point to a controller function and use that controller function to send mail containing these records Commented Mar 17, 2016 at 10:37
  • can you please give me any example
    – Magento 2
    Commented Mar 17, 2016 at 10:39
  • Have you got any controller? I can provide you the code to send email which can be used in controller. And if no controller then first create a module with a controller Commented Mar 17, 2016 at 10:41
  • <form class="form-horizontal" id="careerform" method="post" enctype="multipart/form-data" action="<?php echo $this->getUrl('modulefrontname/') ?>index/sendemail"> your code...</form><script type="text/javascript"> //<![CDATA[ var theForm = new VarienForm('careerform', true); //]]> </script>
    – Arunendra
    Commented Mar 17, 2016 at 10:47

1 Answer 1


i recommend follow this tutorial



create new module that will include the controller too


in your case

<form action='modeulname/controllername/methodname' method="post">

  • Thanks I know how to create controller but i don't know how to connect this form to that controller
    – Magento 2
    Commented Mar 17, 2016 at 10:45
  • you have to add form action='modeulname/controllername/methodname' this is not big issue Commented Mar 17, 2016 at 10:48
  • Check my updated question what is wrong that code. i follow this pierrefay.com/magento-collection-model-forms-63
    – Magento 2
    Commented Mar 17, 2016 at 13:01
  • I don't want to save db i just want to send a mail to admin
    – Magento 2
    Commented Mar 17, 2016 at 13:15
  • you have email code just put it there... Commented Mar 17, 2016 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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