我是Phpmailer的新手,我正在使用它來發送批量電子郵件給一千多人從一個免費帳戶。當我將電子郵件發送給一個或兩個人時,該代碼工作正常,但當我將它發送給每個人(包括我自己)時,它都會發送到垃圾郵件。還有一個問題是電子郵件的詳細信息,它顯示了所有發送給它的人的電子郵件ID,我不希望這樣做。 的代碼如下:使用phpmailer發送批量郵件
//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 = "[email protected]"; // 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
}
Marc B的代碼比我的原始代碼更好 - 我描述的是正確的,但是我的代碼並不反映BCC的建議。你應該按照他的例子來添加一個「to」接收者(通常是你自己,使用AddAddress'''),然後使用AddBCC'作爲列表成員的電子郵件。我編輯了我的代碼來反映這一點。謝謝Marc! – JoLoCo
不僅你不需要每次都設置de MsgHTML,如果插入的文本不同於每個郵件 – Circum