Possible Duplicate: PHPMailer AddAddress()
这是我的代码。
require('class.phpmailer.php'); $mail = new PHPMailer(); $email = 'email1@test.example, email2@test.example, email3@test.example'; $sendmail = "$email"; $mail->AddAddress($sendmail,"Subject"); $mail->Subject = "Subject"; $mail->Body = $content; if(!$mail->Send()) { # sending mail failed $msg="Unknown Error has Occured. Please try again Later."; } else { $msg="Your Message has been sent. We'll keep in touch with you soon."; } }
问题
如果 $email 值只有 1。它会发送。但多个不发送。我应该为此做些什么。我知道在邮件功能中,您必须用逗号分隔多封电子邮件。但不能在 phpmailer 中工作。
最佳答案
您需要为每个收件人调用一次 AddAddress
方法。像这样:
$mail->AddAddress('person1@domain.example', 'Person One');
$mail->AddAddress('person2@domain.example', 'Person Two');
// ..
更好的是,将他们添加为抄送收件人。
$mail->AddCC('person1@domain.example', 'Person One');
$mail->AddCC('person2@domain.example', 'Person Two');
// ..
为方便起见,您应该循环遍历一个数组来执行此操作。
$recipients = array(
'person1@domain.example' => 'Person One',
'person2@domain.example' => 'Person Two',
// ..
);
foreach($recipients as $email => $name)
{
$mail->AddCC($email, $name);
}
关于PHP邮件程序多个地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149452/