需要一个接一个地发送4到5封电子邮件的邮件,因此用于循环,我正在尝试使用PHPMAILER触发电子邮件。但是,仅发送第一封电子邮件地址邮件并保留其显示错误。
注意: EVEN TRIED $ mail-> clearAddresses()
以下是我的邮件代码
<?php
require 'Send_Mail.php';
$var = array("b2.pradeepan@gmail.com","pradeepan.7899@gmail.com","pan6831@gmail.com");
for($i=0;$i<$var;$i++)
{
$to = $var[$i];
$subject = "Bulk Mail";
$body = "dummy loop";
$op = Send_Mail($to,$subject,$body);
}
?>
以下是我的PHPMAILER代码
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "XYZ@gmail.com";
$mail = new PHPMailer();
$mail->ClearAllRecipients();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host = "tls://smtp.gmail.com"; // Amazon SES server, note "tls://" protocol tls://email-smtp.us-west-2.amazonaws.com
$mail->Port = 465; // set the SMTP port
$mail->Username = "XYZ@gmail.com"; // SES SMTP username
$mail->Password = "XYZ"; // SES SMTP password
$mail->SetFrom($from, 'XYZ@gmail.com');
$mail->AddReplyTo($from,'XYZ@gmail.com');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->clearAllRecipients();
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->send()) {
$mail->clearAddresses();
return false;
}
else
{
$mail->clearAddresses();
return true;
}
}
我的代码中的错误是什么.. ??
答案 0 :(得分:0)
尝试更改
for($i=0;$i<$var;$i++)
因为这是一个无限循环
for($i=0;$i<count($var);$i++)
或做一个foreach
foreach($var as $to)