1

I had created the dropdwon list with lab,pharmacy,food,Gym and Nurse and When I select lab it shows some fields(ex:name,city,location,etc) and when I select pharmacy it shows some fields as(ex:medicine name,name,email) in the same it generates for other dropdown lists also.

I need to send the mails with these information with different body for customer,admin and for provider emails.

But I can send for only for lab and not for others.Please help me.

3
  • did you done with attachment? Commented Nov 30, 2015 at 5:47
  • No.they said to stop on that because without that I need to send the email
    – Mouni
    Commented Nov 30, 2015 at 5:54
  • last code i send it was working perfectly and tested too. Commented Nov 30, 2015 at 5:57

1 Answer 1

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



$html="";
if($_POST['servicetype']=='Lab')
    {
      $testname=$_POST['testname'];
$name=$_POST['name'];
$email=$_POST['labemail'];
$mobile=$_POST['labmobile'];

     $city=$_POST['rcity'];
    $zip_code=$_POST['labzip_code'];
     $html .='<p>Name: '.$name.'</p>
     <p>Test Name: '.$testname.'</p>
     <p>Email : '.$email.'</p>
     <p>Mobile Number: '.$mobile.'</p>
     <p>City: '.$city.'</p>
     <p>Zip Code: '.$zip_code.'</p>';
    }else if($_POST['servicetype']=='Pharmacy')
     {
     $medicine=$_POST['medicinename'];

    $testname=$_POST['testname'];
$name=$_POST['pname'];
$email=$_POST['pemail'];
$mobile=$_POST['pmobile'];

     $city=$_POST['pcity'];
    $zip_code=$_POST['pzip_code'];
     $html .='<p> Medicine: '.$medicine.'</p><p> Email: '.$email.'</p>
     <p>Name: '.$name.'</p>


     <p>Mobile Number: '.$labmobile.'</p>
     <p>City: '.$rcity.'</p>
     <p>Zip Code: '.$labzip_code.'</p>';
     }else {



$name=$_POST['fname'];
$email=$_POST['femail'];
$mobile=$_POST['fmobile'];

     $city=$_POST['fcity'];
    $zip_code=$_POST['fzip_code'];
     $html .='<p> Email: '.$email.'</p>
     <p>Name: '.$name.'</p>

     <p>Email : '.$email.'</p>
     <p>Mobile Number: '.$labmobile.'</p>
     <p>City: '.$rcity.'</p>
     <p>Zip Code: '.$labzip_code.'</p>';
     }


  $mail = Mage::getModel('core/email');
  $mail->setToName('admin');
  $mail->setToEmail($email);
  $mail->setBody($html);
  $mail->setSubject('Blood Donor');
  $mail->setFromEmail('[email protected]');
  $mail->setFromName("Labwise");
//$mail->addBcc("[email protected]");
 $mail->setType('html');// YOu can use Html or text as Mail format

 try {
 //$mail->send();

}
 catch (Exception $e) {

}
}
//Customer Mail

function sendMailcustomerAction(){

 $email=$_POST['email'];
 $servicetype=$_POST['servicetype'];
     $testname=$_POST['testname'];
   $name=$_POST['name'];
   $mobile=$_POST['mobile'];
   $city=$POST_['city'];

$html=
'Dear '.$name.',

    <p>We have received your order for '.$testname.'. You will be attended shortly.</p>

    <p>Best Regards,</p>
    <p>Team Labwise.</p>'

 ;
  $mail = Mage::getModel('core/email');
  $mail->setToName($name);
  $mail->setToEmail($email);
  $mail->setBody($html);
  $mail->setSubject('Blood Donor');
  $mail->setFromEmail('[email protected]');
  $mail->setFromName("Labwise");
 //$mail->addBcc("[email protected]");
  $mail->setType('html');// YOu can use Html or text as Mail format

   try {
   $mail->send();

  return '<h2>Your Order has been submitted. Thank you for using labwise.   </h2>';

  }
  catch (Exception $e) {

 return '</h2>Unable to submit.</h2>';

 }
 }

 //service provider details for whose isblooddonor is true

   $connectionresource = Mage::getSingleton('core/resource');
        $readconnection = $connectionresource->getConnection('core_read');  
    if($_POST['servicetype']=='Lab')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.islab=?', '1'
          );
  } else  if($_POST['servicetype']=='Pharmacy')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.pharmacy=?', '1'
          );
  }else  if($_POST['servicetype']=='Gym')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.gym=?', '1'
          );
  }else  if($_POST['servicetype']=='Food')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.food=?', '1'
          );
  }else  if($_POST['servicetype']=='Nurse')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.nurse=?', '1'
          );
  }else  if($_POST['servicetype']=='Physio')
{
        $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.physio=?', '1'
          );
  }
         $alldata =$readconnection->fetchAll($allrecord);
         foreach($alldata as $data)
         {
              sendMailserviceAction($data['email'],$data['name']);
         }

         function sendMailserviceAction($ssemail,$pname){
     //Mage::getModel('sales/order')->load(24999);
     $html="";
if($_POST['servicetype']=='Lab')
    {
      $testname=$_POST['testname'];
$name=$_POST['name'];
$email=$_POST['labemail'];
$mobile=$_POST['labmobile'];

     $city=$_POST['rcity'];
    $zip_code=$_POST['labzip_code'];
     $html .='<p>Name: '.$name.'</p>
     <p>Test Name: '.$testname.'</p>
     <p>Email : '.$email.'</p>
     <p>Mobile Number: '.$mobile.'</p>
     <p>City: '.$city.'</p>
     <p>Zip Code: '.$zip_code.'</p>';
    }else if($_POST['servicetype']=='Pharmacy')
     {
     $medicine=$_POST['medicinename'];

    $testname=$_POST['testname'];
$name=$_POST['pname'];
$email=$_POST['pemail'];
$mobile=$_POST['pmobile'];

     $city=$_POST['pcity'];
    $zip_code=$_POST['pzip_code'];
     $html .='<p> Medicine: '.$medicine.'</p><p> Email: '.$email.'</p>
     <p>Name: '.$name.'</p>


     <p>Mobile Number: '.$labmobile.'</p>
     <p>City: '.$rcity.'</p>
     <p>Zip Code: '.$labzip_code.'</p>';
     }else {



$name=$_POST['fname'];
$email=$_POST['femail'];
$mobile=$_POST['fmobile'];

     $city=$_POST['fcity'];
    $zip_code=$_POST['fzip_code'];
     $html .='<p> Email: '.$email.'</p>
     <p>Name: '.$name.'</p>

     <p>Email : '.$email.'</p>
     <p>Mobile Number: '.$labmobile.'</p>
     <p>City: '.$rcity.'</p>
     <p>Zip Code: '.$labzip_code.'</p>';
     }

     $mail = Mage::getModel('core/email');
      $mail->setToName($pname);
     $mail->setToEmail($ssemail);
     $mail->setBody($html);
     $mail->setSubject('Quick Service');
     $mail->setFromEmail('[email protected]');
     $mail->setFromName("Labwise");
    //$mail->addBcc("[email protected]");
     echo $htm;
    $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('');
     }
     }

    echo sendMailserviceAction();
   echo sendMailcustomerAction();
   echo sendMailAction();

?>

add this code for uploading the file and make sure folder have right of 777

 if( !empty($_FILES["fileToUpload"]["name"])  and $_POST['servicetype']=='Pharmacy')
        { 

            $image_ext = end(explode('.',$_FILES["fileToUpload"]["name"]));
            $allowed_ext =  array('gif','png' ,'jpg','jpeg','pdf','doc','docx','rtf','odt');

            $uploadfilename = md5(substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, rand(1,100).rand(1,100))).str_replace(" ","_",$_FILES["fileToUpload"]["name"]); 
             $source_upl         = $_FILES["fileToUpload"]["tmp_name"];
            $target_path_upl = Mage::getBaseDir('media').DS.'requestquote'.DS.$uploadfilename;  
            if(in_array($image_ext ,$allowed_ext ) ) {
                @move_uploaded_file($source_upl, $target_path_upl);
            }
        }

and this attachment code add it before sending email.

if(file_exists(Mage::getBaseDir('media').DS.'requestquote'.DS.$uploadfilename) )
    {

      $attachment = file_get_contents(Mage::getBaseDir('media').DS.'requestquote'.DS.$uploadfilename);
      $ext = pathinfo($uploadfilename, PATHINFO_EXTENSION);
      $file = new Zend_Mime_Part($attachment);
      $file->filename    = $uploadfilename;
      $file->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
      $file->encoding = Zend_Mime::ENCODING_BASE64;
      $mail->addAttachment($file);
    } 
34
  • For each service type I need to send three mails 1.for customer and 2.for admin 3.for service provider as islab=1 for lab and ispharmacy=1 for pharmacy and isgym=1 for Gym
    – Mouni
    Commented Nov 30, 2015 at 5:58
  • added check in collection and for admin and customer you already set emails. Commented Nov 30, 2015 at 6:05
  • It is only for service type= lab and when islab is checkedand when I select pharmacy,food,gym in the same way it has to send the emails for admin,customer also they have different fields for each service type
    – Mouni
    Commented Nov 30, 2015 at 6:10
  • i added the check in query and also in email. also add foe field in email copy any where you want to send it's work Commented Nov 30, 2015 at 6:12
  • below you have posted upto pharmacy and not for food.Can u please the full code with admin mail and customer mail.I am getting confusing
    – Mouni
    Commented Nov 30, 2015 at 6:18

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.