php
2017-08-14 52 views 0 likes 
0

我需要發送郵件給多個收件人,通知他們的待處理任務。發送電子郵件給不同內容的多個收件人

這是查詢每個收件人的待處理任務的數組。

$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子句的單個查詢。 –

回答

0

而不是運行多個查詢,並要求對DB的,只要運行在您的結果一般查詢和過濾器以提高訪問速度。一旦你有一般查詢陣列,你可以做任何你想做的事

0

我修改了上面的代碼。

$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'; 
     } 
    } 
} 

仍然陣列部分不工作。

相關問題