1 Comment

How to add a controller to send mail

Problem with rewrite
How to create custom sticky admin system messages?

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);

          $contact->save();
       }
        $body ='Hi admin, '.$orderid. 'reason'.$reason;
    $mail = Mage::getModel('core/email');
    $mail->setToName($name);
    $mail->setToEmail('mymail@gmail.com');
    $mail->setBody($body);


    $mail->setSubject('Not Support Pincode');
    $mail->setFromEmail('totaltoys.com');
    $mail->setFromName($name);
    $mail->setType('html');// You can use 'html' or 'text'

    try {
    $mail->send();
    //Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
    //$this->_redirect('');
    }
    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>
       $this->_redirect('test/index/index');
    }

form.phtml

<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> 
       </div>
    <!-- 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>
    </div>

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

    <!-- Reason -->

</form>

Related Posts

  • Rest api url and data format issue (2)
    First of my Guest controller code for a rest api call is as followed: protected function _retrieveCollection() { try { $email = $this->getRequest()->getParams('email'); //check if email exists in db or not $customer = […]
  • Send mail with Shopping Cart Items (1)
    I used Below code for send mail if customer enter Unsupport pincode. It's working fine: <?php class Webkul_Mpperproductshipping_Model_Carrier_LocalDelivery extends Mage_Shipping_Model_Carrier_Abstract { /* Use group alias */ protected $_code = 'mpperproductshipping'; […]
  • Sending custom email for custom module – Magento2 (0)
    I have used the below code for a custom module to send mail. Its working fine. I want to send email for another custom module. So I duplicated the same controller file and changed the required parameters and modulename. But its not working. I dont know what to do. Please someone […]
  • Not getting emails from Magento custom form (1)
    I made a custom form using instructions found at Inchoo. I've created the form and it's appearing properly but the mails are not sending at all. I get an error 'Unable to Send email' which comes from the catch part of the code. Nothing in the system.log or exceptions.log files to […]
  • Sending custom email for custom module – Magento2 (0)
    I have used the below code for a custom module to send mail. Its working fine. I want to send email for another custom module. So I duplicated the same controller file and changed the required parameters and modulename. But its not working. I dont know what to do. Please someone […]
  • Not getting emails from Magento custom form (1)
    I made a custom form using instructions found at Inchoo. I've created the form and it's appearing properly but the mails are not sending at all. I get an error 'Unable to Send email' which comes from the catch part of the code. Nothing in the system.log or exceptions.log files to […]
  • passing data to controller (1)
    I am passing data from below sample .phtml file to controller: <form name="sendsms" action="<?php $params = []; echo $block->getUrl("admin_sms/Sendsms/SendSMS", $params); ?>" method="POST"> Mobile Number: <input class="input-text admin__control__text" […]
  • Magento Send Custom Emails (0)
    I am using Marketplace in my Magento site I needs to send a mail after Seller Save the new product. How to send mail after save product. I added my mail code in Controller but problem is every time i got mail i want to get a mail once in a day controller.php public function […]
  • How to send transactional mail with pdf attachment in magento 2 (2)
    How can i send transactional mail with pdf attachment in magento 2? below is my code: class Post extends MagentoFrameworkAppActionAction { protected $_objectManager; private $_transportBuilder; public function __construct( MagentoBackendAppActionContext […]
  • How to send a form key with post data using ajax to a controller in magento? (3)
    Suppose I have an ajax function like this in a separate js file jQuery.ajax({ url: "/package/module/index/index", type: "POST", data: {name: user_name, dob: date_of_birth},//here i want to send a form key used in magento success: function(response){ […]
Problem with rewrite
How to create custom sticky admin system messages?

1 Comment on this article

Add a comment