2

I had created the dropdown list with fields Lab,Pharmacy,Food and Nurse.When I select the lab it generates the new fields and when I select the pharmacy it generates the new field with upload button.I need to send the mail with these details for lab and pharmacy.

By using below mail function I can send only for lab but when I select pharmacy I could not send any mail.Please help me

<?php

$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.ishospital=?', '1'
    );
} else if ($_POST['servicetype'] == 'Gym') {
    $allrecord = $readconnection->select()->from(array('serviceprovider' => 'mg_serviceprovider'))->where('serviceprovider.isgym=?', '1'
    );
} else if ($_POST['servicetype'] == 'Food') {
    $allrecord = $readconnection->select()->from(array('serviceprovider' => 'mg_serviceprovider'))->where('serviceprovider.isfood=?', '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($email, $pname) {
    //Mage::getModel('sales/order')->load(24999);
    //$location=$_POST['location'];
    $servicetype = $_POST['servicetype'];
    $cemail = $_POST['labemail'];
    $cemail = $_POST['pemail'];
    $cemail = $_POST['femail'];

    if ($_POST['servicetype'] == 'Lab') {
        $cemail = $_POST['labemail'];
        $servicetype = $_POST['servicetype'];
        $testname = $_POST['testname'];
        $name = $_POST['name'];
        $mobile = $_POST['labmobile'];
        $city = $_POST['rcity'];
        $zipcode = $_POST['labzip_code'];
        $html = '
                <p>Service Type: ' . $servicetype . '</p>
                <p>Testname:' . $testname . '</p>
                <p>Name: ' . $name . '</p>
                <p>Email : ' . $cemail . '</p>
                <p>Mobile Number: ' . $mobile . '</p>
                <p>City:' . $city . '</p>
                <p>Zip Code:' . $zipcode . '</p>';
    } else if ($_POST['servicetype'] == 'Pharmacy') {
        $name = $_POST['pname'];
        $medicine = $_POST['medicinename'];
        $cemail = $_POST['pemail'];
        $mobile = $_POST['pmobile'];
        $city = $_POST['pcity'];
        $zipcode = $_POST['pzip_code'];
        $html = '<p>Service Type:' . $servicetype . '</p> <p> Medicine name: ' . $medicine . '</p>
                <p>Name:' . $name . '</p>
                <p> Email: ' . $cemail . '</p>
                <p>Mobile number: ' . $mobile . '</p>
                <p>City:' . $city . '</p>
                <p>Zip Code:' . $zipcode . '</p>';
    } else if ($_POST['servicetype'] == 'Gym') {
        $name = $_POST['fname'];
        $mobile = $_POST['fmobile'];
        $cemail = $_POST['femail'];
        $city = $_POST['fcity'];
        $zipcode = $_POST['fzip_code'];
        $html = '
                <p>Service Type:' . $servicetype . '</p>
                <p>Name: ' . $name . '</p>
                <p>Email : ' . $cemail . '</p>
                <p>Mobile number: ' . $mobile . '</p>
                <p>City:' . $city . '</p>
                <p>Zip Code:' . $zipcode . '</p>';
    } else if ($_POST['servicetype'] == 'Food') {
        $name = $_POST['fname'];
        $cemail = $_POST['femail'];
        $mobile = $_POST['fmobile'];
        $city = $_POST['fcity'];
        $zipcode = $_POST['fzip_code'];

        $html = '
                <p>Service Type:' . $servicetype . '</p>
                <p>Name: ' . $name . '</p>
                <p>Email : ' . $cemail . '</p>
                <p>Mobile number: ' . $mobile . '</p>
                <p>City:' . $city . '</p>
                <p>Zip Code:' . $zipcode . '</p>';
    }
    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);
        }
    }


    $mail = new Zend_Mail();
    $mail->setFrom('admin@labwise.in', "Labwise");


    $mail->addTo($email, $pname);

    $mail->setSubject('Quick Service');
    $mail->setBodyHtml($html);
    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);
    }


    try {
        $mail->send();

        return '<h2> Email Sent.   </h2>';
    } catch (Exception $e) {

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

echo sendMailserviceAction();
?>
1

this is tested code all email are working without any error.

<?php

 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);
            }
        }
      function sendMailAction($uploadfilename){
       //Mage::getModel('sales/order')->load(24999);
        $servicetype=$_POST['servicetype'];



          if($_POST['servicetype']=='Lab'){
          $name=$_POST['name'];
            $servicetype=$_POST['servicetype'];
          $testname=$_POST['testname'];
          $email=$_POST['labemail'];
             $mobile=$_POST['labmobile'];
           $city=$_POST['rcity'];$zipcode=$_POST['labzip_code'];
        $html=
        '<p>Service Type: '.$servicetype.'</p>
       <p>Testname: '.$testname.'</p>
         <p>Name: '.$name.'</p>
          <p>Email:'.$email.'</p>
        <p>Mobile number: '.$mobile.'</p>
         <p>City:'.$city.'</p>
           <p>Zip Code:'.$zipcode.'</p>
        ';
          }
            else if($_POST['servicetype']=='Pharmacy')
          {


     $name=$_POST['pname'];
     $medicine=$_POST['medicinename'];
     $email=$_POST['pemail'];
     $city=$_POST['pcity'];
     $mobile=$_POST['pmobile'];
        $city=$_POST['pcity'];$zipcode=$_POST['pzip_code'];
     $html=
    '<p>Service Type:'.$servicetype.'</p>
    <p>Medicinename: '.$medicine.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
     <p>Mobile number: '.$mobile.'</p>
     <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';

     }
     else if($_POST['servicetype']=='Food')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
     $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
    '<p>Service Type: '.$servicetype.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }

      else if($_POST['servicetype']=='Gym')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
      $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
     $html=
      '<p>Service Type: '.$servicetype.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }
        else if($_POST['servicetype']=='Physio')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
      $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
      $html=
      $html=
      '<p>Service Type: '.$servicetype.'</p>
      <p>Name: '.$name.'</p>
      <p>Email:'.$email.'</p>
      <p>Mobile number: '.$mobile.'</p>
       <p>City:'.$city.'</p>
       <p>Zip Code:'.$zipcode.'</p>';
       }
       else if($_POST['servicetype']=='Nurse')
     {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
        $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
      $html=
      '<p>Service Type: '.$servicetype.'</p>
      <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }



        $mail = new Zend_Mail();
$mail->setFrom('admin@labwise.in',"Labwise");


$mail->addTo($email,$name);

$mail->setSubject('Quick Service');
$mail->setBodyHtml($html);
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);
    }



 $mail->send();

 }

//Customer mail
  function sendMailcustomerAction(){
//Mage::getModel('sales/order')->load(24999);

if($_POST['servicetype']=='Lab'){
 $name=$_POST['name'];
 $servicetype=$_POST['servicetype'];
 $email=$_POST['labemail'];
 $testname=$_POST['testname'];
  $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>';
}
else if($_POST['servicetype']=='Pharmacy')
{ $name=$_POST['pname'];
   $email=$_POST['pemail'];
   $medicine=$_POST['medicinename'];
  $html=

  'Dear '.$name.',

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

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

}

else if($_POST['servicetype']=='Food')
 {
   $name=$_POST['fname'];
   $email=$_POST['femail'];
   $html=
 'Dear '.$name.',

  <p>We have received your order. You will be attended shortly.</p>

  <p>Best Regards,</p>
  <p>Team Labwise.</p>';
 }
 else if($_POST['servicetype']=='Gym')
 {
   $name=$_POST['fname'];
   $email=$_POST['femail'];
   $html=
 'Dear '.$name.',

  <p>We have received your order. You will be attended shortly.</p>

  <p>Best Regards,</p>
  <p>Team Labwise.</p>';
 }
 else if($_POST['servicetype']=='Physio')
 {
   $name=$_POST['fname'];
   $email=$_POST['femail'];
   $html=
 'Dear '.$name.',

  <p>We have received your order. You will be attended shortly.</p>

  <p>Best Regards,</p>
  <p>Team Labwise.</p>';
 }
 else if($_POST['servicetype']=='Nurse')
 {
   $name=$_POST['fname'];
   $email=$_POST['femail'];
   $html=
 'Dear '.$name.',

  <p>We have received your order. 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('Quick Service');
  $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 '<h2>Your Request 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('');
       }
}

  $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 =$reaconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.ishospital=?', '1'
      );
      }else  if($_POST['servicetype']=='Gym')
    {
       $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.isgym=?', '1'
      );
     }else  if($_POST['servicetype']=='Food')
      {
    $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.isfood=?', '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($ccemail,$pname,$uploadfilename){
 //Mage::getModel('sales/order')->load(24999);

 //$location=$_POST['location'];
$servicetype=$_POST['servicetype'];
$cemail=$_POST['labemail'];
$cemail=$_POST['pemail'];
$cemail=$_POST['femail'];

 if($_POST['servicetype']=='Lab')
{
$cemail=$_POST['labemail'];
$servicetype=$_POST['servicetype'];
$testname=$_POST['testname'];
$name=$_POST['name'];
$mobile=$_POST['labmobile'];
$city=$_POST['rcity'];$zipcode=$_POST['labzip_code'];
   $html ='
 <p>Service Type: '.$servicetype.'</p>
 <p>Testname:'.$testname.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile Number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';

  }else if($_POST['servicetype']=='Pharmacy')
 {
 $name=$_POST['pname'];
 $medicine=$_POST['medicinename'];
 $cemail=$_POST['pemail'];
 $mobile=$_POST['pmobile'];
  $city=$_POST['pcity'];$zipcode=$_POST['pzip_code'];
   $html ='<p>Service Type:'.$servicetype.'</p> <p> Medicine name: '.$medicine.'</p>
 <p>Name:'.$name.'</p>
 <p> Email: '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
 }
else if($_POST['servicetype']=='Gym')
{
$name=$_POST['fname'];
$mobile=$_POST['fmobile'];
 $cemail=$_POST['femail'];
 $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
$html ='
 <p>Service Type:'.$servicetype.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
}
else if($_POST['servicetype']=='Food')
{
$name=$_POST['fname'];
$cemail=$_POST['femail'];
$mobile=$_POST['fmobile'];
$city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];

 $html ='
 <p>Service Type:'.$servicetype.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
}



    $mail = new Zend_Mail();
      $mail->setFrom('admin@labwise.in',"Labwise");


  $mail->addTo($ccemail,$pname);

  $mail->setSubject('Quick Service');
    $mail->setBodyHtml($html);
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);
 }


try {
 $mail->send();

return '<h2> Email Sent.   </h2>';

  }
  catch (Exception $e) {

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

 }

    }
   ?>
  • It is not priniting any thing – Mouni Dec 8 '15 at 7:59
  • call this at end of file echo sendMailAction($uploadfilename); – Qaisar Satti Dec 8 '15 at 8:06
  • no it is showing same empty page after submission – Mouni Dec 8 '15 at 8:24
  • is it working for you without any error. – Mouni Dec 8 '15 at 8:48
  • I am not getting customer message for customer.Can you please check it I am getting the attachment mail for servicetype:Lab also.I need the mail attachment only for Pharmacy – Mouni Dec 8 '15 at 9:53
1

try that for sending the email just change the model and attachment code

  $mail = new Zend_Mail();
$mail->setFrom('admin@labwise.in',"Labwise");


$mail->addTo($cemail,$pname);

$mail->setSubject('Blood Donor');
$mail->setBodyHtml($html);
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);
    }


$mail->send();

new and tested code

leave the html before as it is

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


        $mail = new Zend_Mail();
$mail->setFrom('admin@labwise.in',"Labwise");


$mail->addTo($ssemail,$pname);

$mail->setSubject('Blood Donor');
$mail->setBodyHtml($html);
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);
    }


$mail->send();

with your code

<?php
      function sendMailAction(){
       //Mage::getModel('sales/order')->load(24999);
        $servicetype=$_POST['servicetype'];



          if($_POST['servicetype']=='Lab'){
          $name=$_POST['name'];
            $servicetype=$_POST['servicetype'];
          $testname=$_POST['testname'];
          $email=$_POST['labemail'];
             $mobile=$_POST['labmobile'];
           $city=$_POST['rcity'];$zipcode=$_POST['labzip_code'];
        $html=
        '<p>Service Type: '.$servicetype.'</p>
       <p>Testname: '.$testname.'</p>
         <p>Name: '.$name.'</p>
          <p>Email:'.$email.'</p>
        <p>Mobile number: '.$mobile.'</p>
         <p>City:'.$city.'</p>
           <p>Zip Code:'.$zipcode.'</p>
        ';
          }
            else if($_POST['servicetype']=='Pharmacy')
          {


     $name=$_POST['pname'];
     $medicine=$_POST['medicinename'];
     $email=$_POST['pemail'];
     $city=$_POST['pcity'];
     $mobile=$_POST['pmobile'];
        $city=$_POST['pcity'];$zipcode=$_POST['pzip_code'];
     $html=
    '<p>Service Type:'.$servicetype.'</p>
    <p>Medicinename: '.$medicine.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
     <p>Mobile number: '.$mobile.'</p>
     <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';

     }
     else if($_POST['servicetype']=='Food')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
     $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
    '<p>Service Type: '.$servicetype.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }

      else if($_POST['servicetype']=='Gym')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
      $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
     $html=
      '<p>Service Type: '.$servicetype.'</p>
    <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }
        else if($_POST['servicetype']=='Physio')
      {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
      $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
      $html=
      $html=
      '<p>Service Type: '.$servicetype.'</p>
      <p>Name: '.$name.'</p>
      <p>Email:'.$email.'</p>
      <p>Mobile number: '.$mobile.'</p>
       <p>City:'.$city.'</p>
       <p>Zip Code:'.$zipcode.'</p>';
       }
       else if($_POST['servicetype']=='Nurse')
     {
     $name=$_POST['fname'];
     $email=$_POST['femail'];
     $mobile=$_POST['fmobile'];
        $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
     $html=
      $html=
      '<p>Service Type: '.$servicetype.'</p>
      <p>Name: '.$name.'</p>
    <p>Email:'.$email.'</p>
    <p>Mobile number: '.$mobile.'</p>
    <p>City:'.$city.'</p>
     <p>Zip Code:'.$zipcode.'</p>';
     }
    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);
            }
        }


        $mail = new Zend_Mail();
$mail->setFrom('admin@labwise.in',"Labwise");


$mail->addTo($email,$pname);

$mail->setSubject('Blood Donor');
$mail->setBodyHtml($html);
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);
    }

try {
 $mail->send();

return '<h2> Email Sent.   </h2>';

  }
  catch (Exception $e) {

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

  }

        }

      echo sendMailAction();
       ?>

for service provider

    <?php
  $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 =$rea  connection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.ishospital=?', '1'
      );
      }else  if($_POST['servicetype']=='Gym')
    {
       $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.isgym=?', '1'
      );
     }else  if($_POST['servicetype']=='Food')
      {
    $allrecord =$readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.isfood=?', '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($ccemail,$pname){
 //Mage::getModel('sales/order')->load(24999);

 //$location=$_POST['location'];
$servicetype=$_POST['servicetype'];
$cemail=$_POST['labemail'];
$cemail=$_POST['pemail'];
$cemail=$_POST['femail'];

 if($_POST['servicetype']=='Lab')
{
$cemail=$_POST['labemail'];
$servicetype=$_POST['servicetype'];
$testname=$_POST['testname'];
$name=$_POST['name'];
$mobile=$_POST['labmobile'];
$city=$_POST['rcity'];$zipcode=$_POST['labzip_code'];
   $html ='
 <p>Service Type: '.$servicetype.'</p>
 <p>Testname:'.$testname.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile Number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';

  }else if($_POST['servicetype']=='Pharmacy')
 {
 $name=$_POST['pname'];
 $medicine=$_POST['medicinename'];
 $cemail=$_POST['pemail'];
 $mobile=$_POST['pmobile'];
  $city=$_POST['pcity'];$zipcode=$_POST['pzip_code'];
   $html ='<p>Service Type:'.$servicetype.'</p> <p> Medicine name: '.$medicine.'</p>
 <p>Name:'.$name.'</p>
 <p> Email: '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
 }
else if($_POST['servicetype']=='Gym')
{
$name=$_POST['fname'];
$mobile=$_POST['fmobile'];
 $cemail=$_POST['femail'];
 $city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];
$html ='
 <p>Service Type:'.$servicetype.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
}
else if($_POST['servicetype']=='Food')
{
$name=$_POST['fname'];
$cemail=$_POST['femail'];
$mobile=$_POST['fmobile'];
$city=$_POST['fcity'];$zipcode=$_POST['fzip_code'];

 $html ='
 <p>Service Type:'.$servicetype.'</p>
 <p>Name: '.$name.'</p>
 <p>Email : '.$cemail.'</p>
 <p>Mobile number: '.$mobile.'</p>
 <p>City:'.$city.'</p>
 <p>Zip Code:'.$zipcode.'</p>';
}
 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);
        }
    }


    $mail = new Zend_Mail();
      $mail->setFrom('admin@labwise.in',"Labwise");


  $mail->addTo($ccemail,$pname);

  $mail->setSubject('Quick Service');
    $mail->setBodyHtml($html);
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);
 }


try {
 $mail->send();

return '<h2> Email Sent.   </h2>';

  }
  catch (Exception $e) {

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

 }

    }

   echo sendMailserviceAction();
   ?>
  • it is not showing any confirmation message and no mails are coming – Mouni Nov 27 '15 at 6:14
  • forgot about ->loadDefault('email_template') try this and also uploading the file is working or not? – Qaisar Satti Nov 27 '15 at 6:16
  • file is uploading in folder but no mail is getting – Mouni Nov 27 '15 at 6:17
  • update the code kindly check it – Qaisar Satti Nov 27 '15 at 6:19
  • 1
    do me favor accept my all answer on ur question if they help you in that and i will update code.. – Qaisar Satti Dec 4 '15 at 11:26
0

This code is Working for me try this le me know if you have any query

            $mailTemplate = Mage::getModel('core/email_template');
            /* @var $mailTemplate Mage_Core_Model_Email_Template */
            // file attached
            if($post['file']){
                $destination_path = Mage::getBaseDir('media'). DS .'uploads'.DS.$post['file'];
                $mailTemplate->getMail()->createAttachment(
                          file_get_contents($destination_path),
                          Zend_Mime::TYPE_OCTETSTREAM,
                          Zend_Mime::DISPOSITION_ATTACHMENT,
                          Zend_Mime::ENCODING_BASE64,
                          $post['file']
                );
            }
            // after file attached
            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                    null,
                    array('data' => $postObject)
                );
            if (!$mailTemplate->getSentSuccess()) {
                throw new Exception();
            }
  • where I should place this code in my code – Mouni Nov 27 '15 at 11:09
  • can you give reply – Mouni Nov 27 '15 at 11:31
  • In your controller where $post['file'] is file and $destination_path is file path – Vaibhav Ahalpara Nov 27 '15 at 11:53
  • I have not created any controller file – Mouni Nov 27 '15 at 11:53
  • labwise.in/devel/serviceform/submit you have to put this code in submit action in serviceform controller – Vaibhav Ahalpara Nov 27 '15 at 11:55

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.