2

Created the form with fields and added the email code for sending the mail.But I need to send the mail with two different bodies

How can I send Please help me.

My Mail code:

  <?php
   function sendMailAction(){
 //Mage::getModel('sales/order')->load(24999);


 $cname=$_POST['cname'];
 $mobile=$_POST['mobile'];

  $html=
  '
  <p>City: '.$city.'</p>
  <p>Location: '.$location.'</p>
   <p>Name: '.$cname.'</p>
  <p>Email : '.$email.'</p>
  <p>Mobile Number: '.$mobile.'</p>'


 ;
  $mail = Mage::getModel('core/email');
  $mail->setToName($name);
  $mail->setToEmail('some.example@mail.com');
  $mail->setBody($html);
  $mail->setSubject('Booking');
  $mail->setFromEmail('some.example@mail.com');
  $mail->setFromName("example");

 $mail->setType('html');// YOu can use Html or text as Mail format

 try {
 $mail->send();
  //Mage::getSingleton('core/session')->addSuccess('Your Order is successfully Completed');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
 return '<h2>Your Order has been submitted. Thank you for using labwise.   </h2>';
//$this->_redirect('');
}
 catch (Exception $e) {
//Mage::getSingleton('core/session')->addError('Unable to send.');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
return '</h2>Unable to submit.</h2>'; 
//$this->_redirect('');
}
}
 function sendMailcustomerAction(){
 //Mage::getModel('sales/order')->load(24999);
  $email=$_POST['email'];

  $city=$_POST['city'];
  $location=$_POST['location'];

 $cname=$_POST['cname'];
 $mobile=$_POST['mobile'];

$html=
''

 ;
  $mail = Mage::getModel('core/email');
  $mail->setToName($name);
  $mail->setToEmail($email);
  $mail->setBody($html);
  $mail->setSubject('Booking');
  $mail->setFromEmail('Your mail');
  $mail->setFromName("somename");

  $mail->setType('html');// YOu can use Html or text as Mail format

   try {
   $mail->send();
   //Mage::getSingleton('core/session')->addSuccess('Your Order is    successfully Completed');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
  return 'Your Order is Successfully Completed';
  //$this->_redirect('');
  }
  catch (Exception $e) {
  //Mage::getSingleton('core/session')->addError('Unable to send.');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
 return 'Unable to send.'; 
 //$this->_redirect('');
 }
 }
   echo sendMailcustomerAction();
   echo sendMailAction();
   ?>
4

create two function one is send to customer and other is send to owner or else you want to send

function sendMailAction(){
 //Mage::getModel('sales/order')->load(24999);
 $email=$_POST['email'];
  $name=$_POST['testname'];
  $city=$_POST['city'];
  $location=$_POST['location'];

 $cname=$_POST['cname'];
 $mobile=$_POST['mobile'];

  $html=
  '<p>TestName: '.$name.'</p>
  <p>City: '.$city.'</p>
  <p>Location: '.$location.'</p>
   <p>Name: '.$cname.'</p>
  <p>Email : '.$email.'</p>
  <p>Mobile Number: '.$mobile.'</p>'


 ;
  $mail = Mage::getModel('core/email');
  $mail->setToName($name);
  $mail->setToEmail('admin@labwise.in');
  $mail->setBody($html);
  $mail->setSubject('Booking');
  $mail->setFromEmail('admin@labwise.in');
  $mail->setFromName("Labwise");
//$mail->addBcc("admin@labwise.in");
 $mail->setType('html');// YOu can use Html or text as Mail format

 try {
 $mail->send();
  //Mage::getSingleton('core/session')->addSuccess('Your Order is successfully Completed');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
 return '<h2>Your Order has been submitted. Thank you for using labwise.   </h2>';
//$this->_redirect('');
}
 catch (Exception $e) {
//Mage::getSingleton('core/session')->addError('Unable to send.');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
return '</h2>Unable to submit.</h2>'; 
//$this->_redirect('');
}
}
 function sendMailcustomerAction(){
 //Mage::getModel('sales/order')->load(24999);
  $email=$_POST['email'];
  $name=$_POST['testname'];
  $city=$_POST['city'];
  $location=$_POST['location'];

 $cname=$_POST['cname'];
 $mobile=$_POST['mobile'];

$html=
'<p>Dear'.$name.' ,

    We have received your order for '.$name.' . You will be attended shortly.

    Best Regards.
    Team Labwise.</p>'

 ;
  $mail = Mage::getModel('core/email');
  $mail->setToName($name);
  $mail->setToEmail($email);
  $mail->setBody($html);
  $mail->setSubject('Booking');
  $mail->setFromEmail('admin@labwise.in');
  $mail->setFromName("Labwise");
 //$mail->addBcc("contact@labwise.in");
  $mail->setType('html');// YOu can use Html or text as Mail format

   try {
   $mail->send();
   //Mage::getSingleton('core/session')->addSuccess('Your Order is    successfully Completed');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
  return 'Your Order is Successfully Completed';
  //$this->_redirect('');
  }
  catch (Exception $e) {
  //Mage::getSingleton('core/session')->addError('Unable to send.');
 //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
 return 'Unable to send.'; 
 //$this->_redirect('');
 }
 }
   echo sendMailcustomerAction();
   echo sendMailAction();
  • When I click on the submit button it should send the mails to both.Is it possible with the above code. – Mouni Oct 7 '15 at 5:25
  • Should I need to add the same code in the same file for both owner and customer. – Mouni Oct 7 '15 at 5:27
  • yes you can add it will send your both emails – Qaisar Satti Oct 7 '15 at 5:35
  • I am not getting any mails.Can you please check it – Mouni Oct 7 '15 at 5:38
  • I had edited my code as you said.Please check it and suggest me if any thing is wrong. – Mouni Oct 7 '15 at 5:43

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.