如何使用PHPMailer Library

时间:2017-05-09 03:24:20

标签: php

如何发送群发邮件?错误信息是“您必须提供至少一个收件人电子邮件地址”。这是我的代码

$recipient_list = 'recipient1@gmail.com, recipient2@gmail.com';    
$sender_list = 'sender1@gmail.com, sender2@gmail.com';
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isHTML(true);
$mail->Subject = 'Testing';    
$mail->Body    = 'normal <br> <b>bold';

$recipient_address = explode(", ", $recipient_list);

$sender_array = explode(", ", $sender_list);

$sender_address = $sender_array[array_rand($sender_array)];

for($x = 0; $x < count($recipient_address); $x++) {

$mail->setFrom('$sender_address');

$mail->AddCC = '$recipient_list[$x]';

    if (!$mail->send()) {
        echo "<title>Maill Error</title><center><font size='20' color='20'></center></font><br><br>" . $mail->ErrorInfo . " ";
    } else {
        echo "<title>Maill Success</title><center><font size='20' color='green'>Success</center></font><br><br>" . $sender_address . " sending to " . $recipient_list . "<br><br>";
        }
 $mail->clearAddresses();    
 }

1 个答案:

答案 0 :(得分:0)

您忘记添加主要收件人。

$mail->addAddress($recipient);

这是必需的,因为您无法仅向&#34; CC&#34;&#39;

发送电子邮件