5

我对这个比较困惑。

//SMTP servers details
$mail->IsSMTP(); 
$mail->Host = "mail.hostserver.com";  
$mail->SMTPAuth = false;     
$mail->Username = $myEmail;  // SMTP usr
$mail->Password = "****";    // SMTP pass
$mail->SMTPKeepAlive = true;   
$mail->From = $patrickEmail; 
$mail->FromName = "***";    
$mail->AddAddress($email, $firstName . " " . $lastName); 
$mail->WordWrap = 50;                                 
$mail->IsHTML(true);                                  
$mail->Subject = $client_subject;
$mail->Body    = $client_msg;

if($mail->Send())
{

$mail->ClearAllRecipients(); 
$mail->ClearReplyTos();
$mail->ClearCustomHeaders();
...
$mail->From = "DO_NOT_REPLY@..."; 
$mail->FromName = "****";    
$mail->AddAddress($ToEmail1, "***"); //To: (recipients).
$mail->AddAddress($ToEmail2, "***"); //To: (recipients).
$mail->WordWrap = 50;            
$mail->IsHTML(true);             
$mail->Subject = $notification_subject;
$mail->Body    = $notification_msg;
if($mail->Send())
{
...

第一封电子邮件发送良好。第二个没有。这种行为的原因可能是什么?我错过了某种重置吗?


更新:使用不同的邮件服务器似乎可以工作,所以显然这是导致问题的特定邮件服务器的设置。知道那可能是什么吗?

4

8 回答 8

9

一些提供商对在特定时间跨度内可以发送的消息数量施加限制。要确定您的问题是否取决于提供商“速率限制”,您应该尝试在第一次发送后添加暂停。例如:

if ($mail->Send()) {
    sleep(10);  // Seconds
    ...
    if ($mail->Send()) {
        ...
    }
}

然后,通过逐渐降低睡眠时间,您应该能够确定哪个是速率限制。

于 2012-11-29T21:10:50.393 回答
3

试试这个:正如@Felipe Alameda A 提到的Remove $mail->SMTPKeepAlive = true;

// for every mail
if(!$mail->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';        
}
$mail->SmtpClose();
于 2012-12-04T20:24:12.893 回答
3

恕我直言,您需要为每封发送的电子邮件创建新的 PHPMailer 对象。如果您想共享一些通用设置,请使用以下内容:

$mail = new PHPMailer();
/* Configure common settings */

while ($row = mysql_fetch_array ($result)) {
    $mail2 = clone $mail;
    $mail2->MsgHTML("Dear ".$row["fname"].",<br>".$cbody);
    $mail2->AddAddress($row["email"], $row["fname"]);
    $mail2->send();
}
于 2012-11-30T09:34:46.933 回答
2

我认为你的问题是$mail->SMTPAuth = false;

很难相信有不需要身份验证的 ISP 或 SMTP 提供商,即使它们是免费的。

您可以尝试这个来检查错误,而不是检查是否为send()真:

  if ( $mail->IsError() ) { // 
    echo ERROR;
  }
  else {
    echo NO ERRORS;
  }

 //Try adding this too, for debugging:
  $mail->SMTPDebug  = 2;  // enables SMTP debug information

您代码中的其他所有内容看起来都很好。我们经常使用 PHPMailer,从来没有遇到过任何问题

于 2012-12-03T21:36:51.977 回答
1

我个人会尝试采取一些小步骤,例如发送相同的电子邮件..所以只需清除收件人并尝试发送相同的电子邮件(此代码适用于我)。如果此代码通过,您可以继续添加以前的行并在失败的地方进行调试

也许$mail->ClearCustomHeaders();做问题

//SMTP servers details
$mail->IsSMTP(); 
$mail->Host = "mail.hostserver.com";  
$mail->SMTPAuth = false;     
$mail->Username = $myEmail;  // SMTP usr
$mail->Password = "****";    // SMTP pass
$mail->SMTPKeepAlive = true;   
$mail->From = $patrickEmail; 
$mail->FromName = "***";    
$mail->AddAddress($email, $firstName . " " . $lastName); 
$mail->WordWrap = 50;                                 
$mail->IsHTML(true);                                  
$mail->Subject = $client_subject;
$mail->Body    = $client_msg;
// all above is copied
if($mail->Send()) {
  sleep(5);
  $mail->ClearAllRecipients(); 
  $mail->AddAddress('another@email.com'); //some another email

}
...
于 2012-12-04T09:47:23.623 回答
1

试试下面的例子。,

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

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();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address1 = "whoto@otherdomain.com";
$address2 = "whoto@otherdomain.com";

$mail->AddAddress($address1, "John Doe");
$mail->AddAddress($address2, "John Peter");

$mail->AddAttachment("images/phpmailer.gif");      // attachment if any
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if any

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>

注意:更好的是,您可以将多用户电子邮件和名称设置为 ARRAY,例如

<?php

    $recipients = array(
       'person1@domain.com' => 'Person One',
       'person2@domain.com' => 'Person Two',
       // ..
    );

    foreach($recipients as $email => $name)
    {
       $mail->AddCC($email, $name);
    }

    (or)

    foreach($recipients as $email => $name)
    {
       $mail->AddAddress($email, $name);
    }
?>

我认为这可以帮助您解决问题。

于 2012-12-05T06:11:55.270 回答
1

我认为你在这里遇到了组织问题。

我建议:

  1. 设置您的设置(SMTP、用户、通行证)
  2. 使用来自包含消息的数组和地址的信息创建新的电子邮件对象
  3. 发送电子邮件
  4. 转到第 2 步
于 2012-12-04T17:29:33.320 回答
1

关键可能在于您省略的部分。两封邮件的发件人域名是否相同?否则 SMTP 主机可能会将其视为中继尝试。如果您有权访问 SMTP 服务器日志,请检查这些;他们可能会提供线索。

此外,检查$mail->ErrorInfo说什么......它可能会告诉你问题是什么。

于 2012-11-29T14:38:25.193 回答