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

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

问题描述:

我需要发送邮件给多个收件人,通知他们的待处理任务。发送电子邮件给不同内容的多个收件人

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

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

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

​​

//获得结果并将邮件发送给相关收件人。但是我还没有设置收件人部分。

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'; 
      } 
     } 
} 
+0

mysqli_query()不会为您查询多个查询的结果。您需要执行多个查询或使用带有复合WHERE子句的单个查询。 –

而不是运行多个查询,并要求对DB的,只要运行在您的结果一般查询和过滤器以提高访问速度。一旦你有一般查询阵列,你可以做任何你想做的事

我修改了上面的代码。

$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 = mysqli_query($dbcon,$pending[0]); 
$result1 = mysqli_query($dbcon,$pending[1]); 

$address=array('mail_1','mail_2'); 
if(!$result||!$result1) 
{ 
    die('Could not get data: ' . mysqli_error()); 
} 
else 
{ 
    $count= mysqli_num_rows($result); 
    $count1= mysqli_num_rows($result1); 
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';*/ 

    $count_c=array($count,$count1); 
    foreach($count_c as $cunt) //Not working 
    { 
     foreach($address as $addr) 
     { 
      $mail->addAddress($addr, 'Mailer'); 
      $mail->Subject = 'Notification: User Management System'; 
      $mail->Body = 'Dear User, <br> <br>You have '.$cunt.' 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'; 
     } 
    } 
} 

仍然阵列部分不工作。