PHP Mailer多个地址 [英] PHP mailer multiple address
本文介绍了PHP Mailer多个地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
PHPMailer AddAddress()
Possible Duplicate:
PHPMailer AddAddress()
这是我的代码.
require('class.phpmailer.php');
$mail = new PHPMailer();
$email = 'email1@test.com, email2@test.com, email3@test.com';
$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中工作.
The Problem
if $email value 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.
推荐答案
您需要为每个收件人调用一次AddAddress
方法.像这样:
You need to call the AddAddress
method once for every recipient. Like so:
$mail->AddAddress('person1@domain.com', 'Person One');
$mail->AddAddress('person2@domain.com', 'Person Two');
// ..
更好的是,将它们添加为抄送"收件人.
Better yet, add them as Carbon Copy recipients.
$mail->AddCC('person1@domain.com', 'Person One');
$mail->AddCC('person2@domain.com', 'Person Two');
// ..
为使事情变得简单,您应该遍历数组以完成此操作.
To make things easy, you should loop through an array to do this.
$recipients = array(
'person1@domain.com' => 'Person One',
'person2@domain.com' => 'Person Two',
// ..
);
foreach($recipients as $email => $name)
{
$mail->AddCC($email, $name);
}
这篇关于PHP Mailer多个地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文