Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用phpmailer发送批量邮件_Php_Email_Phpmailer - Fatal编程技术网

使用phpmailer发送批量邮件

使用phpmailer发送批量邮件,php,email,phpmailer,Php,Email,Phpmailer,我是Phpmailer的新手,我正在使用它从noreply帐户向一千多人发送批量电子邮件。当我将电子邮件发送给一两个人时,代码运行良好,但当我将其发送给所有人(包括我自己)时,它会变成垃圾邮件。还有一个问题是在电子邮件的详细信息中,它显示了所有收到邮件的人的电子邮件ID,我不希望这样做。 代码如下: //date_default_timezone_set('America/Toronto'); require_once('../class.phpmailer.php'); //include(

我是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('noreply@mydomain.com', 'List manager');
$mail->AddReplyTo('list@mydomain.com', '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
}

我认为您正在将新地址添加到已发送的电子邮件中--因此第一封电子邮件将发送给一个人,第二封电子邮件将发送给同一个人加上另一个人,第三封将发送给这两个人再加上一个人,依此类推

另外,我不认为每次都需要设置AltBody和MsgHTML

您应该首先将所有地址添加到密件抄送字段,然后发送

所以试试

// rest of code first
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("you@example.com")

$ids = mysql_query($select, $connection) or die(mysql_error());
while ($row = mysql_fetch_row($ids)) {
  $mail->AddBCC($row[0]);
}

$mail->Send();//Sends the email
使用密件抄送(盲拷贝)隐藏收件人列表。
与垃圾邮件问题相关的是,它取决于收件人的电子邮件提供商哪些是垃圾邮件,哪些不是垃圾邮件,还有很多因素。

正如JoLoCo指出的那样,
AddAddress()
方法只是将一个新地址添加到现有的收件人列表中。因为你是作为一个添加/发送循环来做的,所以你向第一个接收者发送了大量的副本,向第二个接收者发送的副本少了一份,以此类推

您需要的是:

while($row = mysql_fetch_row(...)) {
   $mail->AddAddress($row[0]);
   $mail->send();
   $mail->ClearAllRecipients(); // reset the `To:` list to empty
}
另一方面,由于这会向您的邮件服务器发送大量单一电子邮件,另一种选择是生成一封电子邮件,并以密件传给所有收件人

$mail->AddAddress('you@example.com'); // send the mail to yourself
while($row = mysql_fetch_row(...)) {
   $mail->AddBCC($row[0]);
}
$mail->send();

这个选项很可能更可取。您只生成一封电子邮件,并让邮件服务器处理向每个收件人发送副本的繁重工作。

Marc B的代码比我的原始代码要好——我描述得没错,但我的代码没有反映密件抄送的建议。你应该效仿他的例子,在列表成员的电子邮件中添加一个“收件人”(通常是你自己,使用
AddAddress
),然后使用
AddBCC
。我编辑了代码以反映这一点。谢谢你,马克!您不仅不需要每次都设置de-MsgHTML,而且如果插入的文本在每封邮件中都不同,则可能会产生不良影响密件抄送的问题是它将成为垃圾邮件。我在两个或三个不同的帐户上进行了测试,所有这些帐户都是垃圾邮件。你必须做其他事情,比如实现域密钥和SPF记录,或者将你的邮件移动到更“合法”的发送平台,以缓解垃圾邮件问题。否则,只需切换到使用to:即可,因为PHP必须为每个收件人生成一封电子邮件