将电子邮件发送给具有不同内容的多个收件人

时间:2017-08-14 16:15:13

标签: php

我需要向多个收件人发送邮件,通知他们待处理的任务。

这是用于查询每个收件人的待处理任务的数组。

$pending = array(
"select * from user WHERE status='processing' and reason!='Out of island'",
"select * from user WHERE status='processing' and reason!='Out of island'", //DGM-HR 
"select * from user WHERE status='new'", //DGM-ITAS
"select * from user WHERE status='processing' and reason='Out of island'", //Manager-HR
"select * from user where CRM_Status='pending'",  //CRM-Eng
"select * from user where OSS_Status='pending'",  //OSS-Eng
"select * from user where BSS_Status='pending'"  //BSS-Eng
);

//从每个查询中检索结果并将其传递给另一个数组。这个数组不起作用。

$pending = implode("\r\n", $pending);
$result = array(
mysqli_query($dbcon,$pending)
);

//获取结果并将邮件发送给相关收件人。但我还没有建立收件人部分。

foreach($result as $result1)
{
        if(!$result1) 
        {
            die('Could not get data: ' . mysqli_error());
        }
        else
        {
            foreach($result1 as $count)
            {
                $count= mysqli_num_rows($result1);
                $mail->addAddress('to_mail', 'to'); //Only for single recipient
                $mail->Subject = 'Notification: User Management System';
                $mail->Body    = 'Dear User, <br> <br>You have '.$count.' records which is pending for your approval.<br> Please engage for the relevant tasks.<br><br>';
                $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
            }
        }   
}

1 个答案:

答案 0 :(得分:0)

只需运行常规查询并过滤结果即可快速访问,而不是运行多个查询并询问数据库。一旦有了通用查询的数组,就可以做任何你想做的事情