使用单个destinatary发送多封电子邮件

时间:2015-03-13 06:46:34

标签: php email

我想向多个destinataries发送电子邮件,但在destinatary只显示电子邮件,而不是其他邮件

例如:

而不是:

mail('juanito@gmail.com,jua@gmail.com,juana@gmail.com', $asunto, $html,$header);

邮箱中的

http://prntscr.com/6g4zkz

可以在邮箱中:http://prntscr.com/6g4zz1

但发送3封电子邮件?

修改

我解决了这样的问题:

while ($resulta = $dati->fetch_array()) {
            $email = $resulta['email'];
            mail($email, $asunto, $html,$header);
        }

唯一的问题是我不知道如何返回真或假:

public function feed_mail($id){
        $mysqli = $this->connection();
        $data = $mysqli->query("SELECT * FROM feed");
        $dati = $mysqli->query("SELECT * FROM feed");
        $dato = $mysqli->query("SELECT * FROM blog where id='$id'");
        $resultado = $dato->fetch_array();
        $title = $resultado['title'];
        $date = $resultado['date'];
        $autor= $resultado['author'];
        $body = base64_decode($resultado['body']);
        $asunto = 'Ortoflex - '.$title;
        while ($resultados = $data->fetch_array()) {
        $html = '<div style="width:80%;padding: 100px; background: #E4EDF6;border:10px solid #000000;">';
                        $html .= '<h1><b>'.$title.'</b></h1>';
                        $html .= '<br>';
                        $html .= $date;
                        $html .= '<hr>';
                        $html .= '<br>';
                        $html .= $body;
                        $html .= '<hr><br>';
                        //while ($resultados = $data->fetch_array()) {
                        $html .= '<a href="'.$this->url.'unsuscribe?hash='.$resultados['hash'].'">Anular Suscripci&oacute;n</a>';   
                        }
                        $header .="MIME-Version: 1.0\n"; 
        $header .= "Content-type: text/html; charset=iso-8859-1\n"; 
        $header .="From: Ortoflex.mx<feed@ortoflex.mx>\n";
        $header .="Return-path: feed@ortoflex.mx\n";
        $header .="X-Mailer: PHP/". phpversion()."\n";
        //$header .= "Bcc: ".$item."\r\n";
        $to = 'private-feed@ortoflex.mx';       
while ($resulta = $dati->fetch_array()) {
            $email = $resulta['email'];
            mail($email, $asunto, $html,$header);
        }

            return true;

    }

3 个答案:

答案 0 :(得分:1)

通过将您的destinataries放入BCC来发送邮件。您的收件人无法看到其他人的电子邮件地址。以下是示例代码

将您的电子邮件字段设置为null和

$to=array();
$headers .= 'From: Jack.com <admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers);

答案 1 :(得分:0)

使用此: -

$headers .= 'From: SmsGratisan.com <admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers)

答案 2 :(得分:0)

标题中的用户BCC

$to=array(); 
$headers .= 'From: Jack.com <admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n"; 
if(mail(null, $title, $content, $headers))
  return true; 
else 
  return false;

将字符串转换为数组并迭代它

$ids='juanito@gmail.com,jua@gmail.com,juana@gmail.com'
$emails[]=explode(" ", $ids);
$errors[]="";
for($i=0;$i<count($emails);$i++)
{
  if(!mail($emails[$i], $asunto, $html,$header)){
      $errors[]="Email function didn't work for".$emails[$i];
   }

}

另一种方法,如果你想知道确切的错误(通过使用try和catch)

for($i=0;$i<count($emails);$i++)
{
  try{
     mail($emails[$i], $asunto, $html,$header);
     }
    catch(Exception $exception){
     $errors[]=$exception->getMessage(). " <- exception for email   ".$emails[$i];
    }   
}