2015-04-05 65 views
-1

我需要發送存儲在數據庫中的多個電子郵件發送保存在數據庫中的多個電子郵件

$mysqli = $this->connection(); //connect to db 
$dati = $mysqli->query("SELECT * FROM feed where active='1'");//select emails 
while ($resulta = $dati->fetch_array()) { //while to show 
      $email = $resulta['email']; //each mail 
} 

上面的代碼是什麼使用 IM,但我需要用郵件功能發送電子郵件的同時 外,如果發送返回正確實現的功能:

這是功能:

function feed_mail($id){ 
$mysqli = $this->connection(); //connect to db 
    $dati = $mysqli->query("SELECT * FROM feed where active='1'");//select emails 
    while ($resulta = $dati->fetch_array()) { //while to show 
       $email = $resulta['email']; //each mail 
    } 
if(mail($email, $asunto, $html,$header)){ 
return true; 
return false; 
} 
} 

$電子郵件將被存儲在數據庫01的每個郵件$ asunto,$ html,$ header我沒有在這裏添加代碼

所以我如何發送每封電子郵件?

回答

0
function feed_mail($id){ 
    $mysqli = $this->connection(); //connect to db 
    $dati = $mysqli->query("SELECT * FROM feed where active='1'");//select emails 
    while ($resulta = $dati->fetch_array()) { //while to show 
     $email = $resulta['email']; //each mail 

     if(mail($email, $asunto, $html,$header)){ 
      continue; 

     }else{ 
      return false; 
     } 
    } 
    return true; 
} 
0

你是正在尋找這樣的事情:

請將您$asunto,$html,$headeras你沒有提到他們在你的問題。

<?php 
function feed_mail($id){ 
$mysqli = $this->connection(); //connect to db 
    $dati = $mysqli->query("SELECT * FROM feed where active='1'");//select emails 
    $emailArr = array(); 
    while ($resulta = $dati->fetch_array()) { //while to show 
       array_push($emailArr,$resulta['email']); 
    } 
    foreach($emailArr as $emails){ 
     if(mail($emails, $asunto, $html,$header)){ 
    return true; 
     }else{ 
    return false; 
     } 
    } 
} 
?> 
0

您還可以趕上所有的電子郵件到一個數組

$email = array(); 
while ($resulta = $dati->fetch_array()) { //while to show 
    $email[] = $resulta['email']; //each mail 
} 

,然後把他們都在一個電子郵件(或者至少在一個電子郵件更多)連接它們作爲頭CC。閱讀article

+0

怎麼樣?我發了 ? – Emilo 2015-04-05 09:15:12

+0

閱讀文章,你會現在它。添加標頭,如$標頭。=「CC:[email protected],[email protected],.. \ r \ n」; – AdamM 2015-04-05 09:27:26

相關問題