How to send mail by getting the details from database?
-
13-12-2019 - |
Question
I had created a dropdown list with fields lab,pharmacy and food.When
1.I select the lab it has to send the mail for those islab checkbox is true.
2.when I select the pharmacy it has to send the mail for those ispharmacy checkbox is true and in the same way for food.
I have tried for islab but I could not add for rest of them. Please help me.
mail.phtml
<?php
$connectionresource = Mage::getSingleton('core/resource');
$readconnection = $connectionresource->getConnection('core_read');
$allrecord = $readconnection->select()->from(array('serviceprovider'=>'mg_serviceprovider'))->where('serviceprovider.islab=?', '1'
);
$alldata =$readconnection->fetchAll($allrecord);
foreach($alldata as $data)
{
sendMailserviceAction($data['email'],$data['name']);
}
function sendMailserviceAction($email,$pname){
//Mage::getModel('sales/order')->load(24999);
$cemail=$_POST['email'];
$bloodgroup=$_POST['bloodgroup'];
$unitsrequired=$_POST['unitsrequired'];
$requireddate=$_POST['requiredby'];
$rcity=$_POST['rcity'];
$city=$_POST['city'];
$hospital=$_POST['hospital'];
//$location=$_POST['location'];
$name=$_POST['name'];
$mobile=$_POST['mobile'];
$yourbloodgroup=$_POST['yourbloodgroup'];
$html=
'Hi,
<p>
<p><h2>Requisition Details:</h2> </p>
<p>Bloodgroup: '.$bloodgroup.'</p>
<p>Units Required:'.$unitsrequired.'</p>
<p>Required By:'. $requireddate.'</p>
<p>City: '.$rcity.'</p>
<p>Hospital:'.$hospital.'</p>
<p><h2>Seeker Details:</h2></p>
<p>Name: '.$name.'</p>
<p>Email : '.$cemail.'</p>
<p>Mobile Number: '.$mobile.'</p>
<p>City: '.$city.'</p>
<p>YourBloodgroup:'.$yourbloodgroup.'</p>'
;
$mail = Mage::getModel('core/email');
$mail->setToName($pname);
$mail->setToEmail($email);
$mail->setBody($html);
$mail->setSubject('Blood Donor');
$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('');
}
}
echo sendMailserviceAction();
?>
Solution
use this query for or condition..
$connectionresource = Mage::getSingleton('core/resource');
$readconnection = $connectionresource->getConnection('core_read');
$query="SELECT *
FROM mg_serviceprovider where islab='1' or ispharmacy='1'";
$alldata =$readconnection->fetchAll($query);
foreach($alldata as $data)
{
sendMailserviceAction($data['email'],$data['name']);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange