我使用swiftmailer发送邮件。
我的代码是:
require_once APPPATH.'libraries/swift_mailer/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('mail.---.com', 25)
->setUsername('----')
->setPassword('---');
$mailer = Swift_Mailer::newInstance($transport);
/* database queries */
$get_count = $this->db->query("SELECT client_id, email FROM `tbl_client`")->result();
foreach($get_count as $count) {
$id = $count->client_id;
$c_email = $count->email;
$today_leads = $this->db->query("SELECT COUNT(*) leads_count FROM `tbl_leads` WHERE DATE(leads_update_on) = curdate() AND client_id = $id")->row();
$today_leads = $today_leads->leads_count;
$till_date = $this->db->query("SELECT COUNT(*) leads_till_date FROM `tbl_leads` WHERE client_id = $id")->row_array();
$till_date_leads = $till_date['leads_till_date'];
$get_project = $this->db->query("SELECT p.project_id, p.project_name FROM `tbl_project` p INNER JOIN tbl_client c ON p.client_id = c.client_id WHERE c.client_id = $id")->result();
if((count($get_project) )> 0 ){
foreach($get_project as $project) {
$project_name = $project->project_name;
$project_id = $project->project_id;
$source_count = $this->db->query("SELECT COUNT(*) count_source, source FROM `tbl_leads` WHERE DATE(leads_update_on) = curdate() AND project_id=$project_id AND client_id=$id GROUP BY source")->result();
if((count($source_count) )> 0){
ob_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/application/views/email_templates/daily_leads_cron.php');
$body123 = ob_get_contents();
ob_end_clean();
//echo $body123;exit;
$message = Swift_Message::newInstance("Daily Report")
->setFrom(array('abc@xyz.in' => 'abc'))
->setTo(array($c_email))
->setBody($body123, 'text/html')
;
$mailer->send($message);
}
}
}
else {
echo "else";
}
}
在daily_leads_cron.php
中,有一个带php foreach
循环的html文件。我已使用daily_leads_cron.php
测试了//echo $body123;exit;
文件的输出,并且工作正常。
问题是邮件的接收者收到两封电子邮件而不是一封,而这些邮件是BLANK
,没有任何内容。我测试了所有循环,没有任何错误。任何人都可以告诉我为什么会这样。