2015-04-05 67 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

相关问题