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