php PHP邮件多地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3149452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP mailer multiple address
提问by Jorge
Possible Duplicate:
PHPMailer AddAddress()
Here is my code.
这是我的代码。
require('class.phpmailer.php');
$mail = new PHPMailer();
$email = '[email protected], [email protected], [email protected]';
$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.";
}
}
The Problem
if $emailvalue is only 1. It will send. But multiple don't send. What should I do for this. I know that in mail function you have to separate multiple emails by comma. But not working in phpmailer.
该问题
如果$电子邮件值仅为1。它会发送。但多个不发送。我该怎么做。我知道在邮件功能中,您必须用逗号分隔多封电子邮件。但不能在 phpmailer 中工作。
回答by Alan Orozco
You need to call the AddAddressmethod once for every recipient. Like so:
您需要AddAddress为每个收件人调用一次该方法。像这样:
$mail->AddAddress('[email protected]', 'Person One');
$mail->AddAddress('[email protected]', 'Person Two');
// ..
Better yet, add them as Carbon Copy recipients.
更好的是,将它们添加为 Carbon Copy 收件人。
$mail->AddCC('[email protected]', 'Person One');
$mail->AddCC('[email protected]', 'Person Two');
// ..
To make things easy, you should loop through an array to do this.
为方便起见,您应该遍历一个数组来执行此操作。
$recipients = array(
'[email protected]' => 'Person One',
'[email protected]' => 'Person Two',
// ..
);
foreach($recipients as $email => $name)
{
$mail->AddCC($email, $name);
}

