使用phpmailer批量发送邮件
我是 Phpmailer 的新手,我正在使用它从 noreply 帐户向一千多人发送批量电子邮件。当我将电子邮件发送给一两个人时,该代码工作正常,但当我将其发送给每个人(包括我自己)时,它就会变成垃圾邮件。还有一个问题是电子邮件的详细信息,它显示了所有接收者的电子邮件 ID,而我不希望这样做。 代码如下:
//date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp1.site.com;smtp2.site.com";
$mail->SMTPAuth = true;// enable SMTP authentication
$mail->SMTPKeepAlive = true;// SMTP connection will not close after each email sent
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('[email protected]', 'List manager');
$mail->AddReplyTo('[email protected]', 'List manager');
$mail->Subject = 'Newsletter';
$ids = mysql_query($select, $connection) or die(mysql_error());
while ($row = mysql_fetch_row($ids)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress($row[0]);
$mail->Send();//Sends the email
}
I am new to Phpmailer and I am using it to send a bulk Email to over a thousand people from a noreply account. The code works fine when I send the Email to one or two people but when I send it to everybody (including myself) it goes to spam. One more problem is in details of the Email it shows the Email ids of all the people to whom it was sent which I don't want it to do.
The code is as follows:
//date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp1.site.com;smtp2.site.com";
$mail->SMTPAuth = true;// enable SMTP authentication
$mail->SMTPKeepAlive = true;// SMTP connection will not close after each email sent
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('[email protected]', 'List manager');
$mail->AddReplyTo('[email protected]', 'List manager');
$mail->Subject = 'Newsletter';
$ids = mysql_query($select, $connection) or die(mysql_error());
while ($row = mysql_fetch_row($ids)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress($row[0]);
$mail->Send();//Sends the email
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 JoLoCo 指出的,
AddAddress()
方法只是将新地址添加到现有收件人列表中。由于您将其作为添加/发送循环进行,因此您将向第一个收件人发送大量重复副本,向第二个收件人发送更少的副本,等等......您需要的是:
另一方面,由于这会向您的邮件服务器发送大量单封电子邮件,因此另一种选择是生成一封单封电子邮件,然后密件抄送所有收件人。
这个选项很可能是更可取的。您只需生成一封电子邮件,然后让邮件服务器处理向每个收件人发送副本的繁重工作。
As JoLoCo points out, the
AddAddress()
method just ADDS a new address to the existing recipient list. And since you're doing it as an add/send loop, you're sending out a helluva lot of duplicate copies to the first recipient, one less to the second, etc...What you need is:
On the other hand, since this spams your mail server with a lot of single emails, another option is to generate one SINGLE email, and BCC all the recipients.
This option is most likely preferable. You only generate a single email, and let the mail server handle the heavy duty work of sending out copies to each recipient.
我认为您正在将新地址添加到已发送的电子邮件中 - 因此第一封电子邮件将发送给一个人,发送的第二封电子邮件将发送给同一个人加上另一个人,第三封电子邮件将发送给这两个人再加一个人, 等等。
另外,我认为您不需要每次都设置 AltBody 和 MsgHTML。
您应该先将所有地址添加到密件抄送字段,然后发送。
所以尝试...
I think you're adding the new address to the email already sent -- so the first email will go to one person, the second email sent will go to that same person plus another, the third one will go to those two plus one more, and so on.
Also, I don't think you need to set the AltBody and MsgHTML every time.
You should add all the addresses to the BCC field first, then send.
So try...
使用 BCC(密件抄送)隐藏收件人列表。
与垃圾邮件问题相关,这取决于收件人的电子邮件提供商什么会成为垃圾邮件,什么不会,并且有很多因素。
Use BCC (Blind Carbon Copy) to hide the list of recipients.
Related to the spam problem, it depends on the email provider of the recipients what is going to spam, and what is not, and there are many factors out there.