I am rather puzzled with this one.
我对这个有点迷惑。
//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())
{
...
The first email sends fine. The second one doesn't. What could be the reason for that behavior? Am I missing some kind of reset?
第一封邮件发送得很好。第二个不是。这种行为的原因是什么?我是不是漏掉了什么重置?
Update: using a different mail server seems to work so apparently it's a setting of that specific mail server causing problems. Any idea what that could be?
更新:使用不同的邮件服务器似乎可以工作,所以很明显,这是一个特定邮件服务器的设置导致了问题。知道那是什么吗?
8 个解决方案
#1
7
Some providers impose restrictions on the number of messages that can be sent within a specific time span. To determine if your problem depends by a provider "rate limit", you should try to add a pause after the first send. For example:
一些提供者对可以在特定时间范围内发送的消息数量进行限制。要确定您的问题是否取决于提供者“速率限制”,您应该尝试在第一次发送之后添加一个暂停。例如:
if ($mail->Send()) {
sleep(10); // Seconds
...
if ($mail->Send()) {
...
}
}
Then, by progressively lowering the sleep time, you should be able to determine which is the rate limit.
然后,通过逐步降低睡眠时间,您应该能够确定哪个是速率限制。
#2
3
IMHO you need to create new PHPMailer object for every sent email. If you want to share some common setup, use something like this:
IMHO您需要为每个发送的电子邮件创建新的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();
}
#3
3
Try this: As @Felipe Alameda A mentioned Remove $mail->SMTPKeepAlive = true;
试试这个:当@Felipe Alameda提到删除$mail->SMTPKeepAlive = true;
// for every mail
if(!$mail->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mail->SmtpClose();
#4
2
I think your problem is $mail->SMTPAuth = false;
我认为你的问题是$mail->SMTPAuth = false;
It is hard to believe there are ISP or SMTP providers that don't require authentication, even if they are free.
很难相信有ISP或SMTP提供商不需要身份验证,即使它们是免费的。
You may try this to check for errors instead of or in addition to checking for send()
true:
您可以尝试检查错误,而不是检查send() true:
if ( $mail->IsError() ) { //
echo ERROR;
}
else {
echo NO ERRORS;
}
//Try adding this too, for debugging:
$mail->SMTPDebug = 2; // enables SMTP debug information
Everything else in your code looks fine. We use PHPMailer a lot and never had any problems with it
代码中的其他内容看起来都很好。我们经常使用PHPMailer,从来没有遇到过任何问题
#5
1
The key may lie in the parts you have omitted. Is the domain of the sender of both emails the same? Otherwise the SMTP host may see this as a relay attempt. If you have access to the SMTP server logs, check these; they might offer a clue.
关键可能在于你漏掉的部分。这两封邮件的发件人的域相同吗?否则,SMTP主机可能会将此视为继电器尝试。如果您有访问SMTP服务器日志的权限,请检查这些日志;他们可能会提供一个线索。
Also, check what $mail->ErrorInfo
says... it might tell you what the problem is.
另外,检查$mail->ErrorInfo说什么…它可能会告诉你问题出在哪里。
#6
1
i personally would try to make small steps like sending same email.. so just clear recipients and try to send identical email (this code works for me). If this code passes you can continue to adding back your previous lines and debug where it fails
我个人会尝试做一些小步骤,比如发同样的邮件。所以,只需要清除收件人并尝试发送相同的电子邮件(此代码适用于我)。如果此代码通过,您可以继续添加以前的行并调试失败的地方。
and maybe $mail->ClearCustomHeaders();
doing problems
也许邮件- > 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
}
...
#7
1
Try with the following example.,
试试下面的例子。
<?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!";
}
?>
Note : Better you can make a multiple user email and name as an ARRAY, like
注意:更好的方法是,您可以创建多个用户电子邮件和名称作为数组,比如。
<?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);
}
?>
i think this may help you to resolve your problem.
我认为这可能有助于你解决你的问题。
#8
1
I think you've got organizational problems here.
我认为你们在组织上有问题。
I recommend:
我建议:
- Set your settings (SMTP, user, pass)
- 设置设置(SMTP, user, pass)
- Create new email object with info from an array holding messages and to addresses
- 创建新的电子邮件对象,包含来自包含消息和地址的数组的信息
- Send email
- 发送电子邮件
- Goto step 2
- 转到步骤2
#1
7
Some providers impose restrictions on the number of messages that can be sent within a specific time span. To determine if your problem depends by a provider "rate limit", you should try to add a pause after the first send. For example:
一些提供者对可以在特定时间范围内发送的消息数量进行限制。要确定您的问题是否取决于提供者“速率限制”,您应该尝试在第一次发送之后添加一个暂停。例如:
if ($mail->Send()) {
sleep(10); // Seconds
...
if ($mail->Send()) {
...
}
}
Then, by progressively lowering the sleep time, you should be able to determine which is the rate limit.
然后,通过逐步降低睡眠时间,您应该能够确定哪个是速率限制。
#2
3
IMHO you need to create new PHPMailer object for every sent email. If you want to share some common setup, use something like this:
IMHO您需要为每个发送的电子邮件创建新的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();
}
#3
3
Try this: As @Felipe Alameda A mentioned Remove $mail->SMTPKeepAlive = true;
试试这个:当@Felipe Alameda提到删除$mail->SMTPKeepAlive = true;
// for every mail
if(!$mail->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mail->SmtpClose();
#4
2
I think your problem is $mail->SMTPAuth = false;
我认为你的问题是$mail->SMTPAuth = false;
It is hard to believe there are ISP or SMTP providers that don't require authentication, even if they are free.
很难相信有ISP或SMTP提供商不需要身份验证,即使它们是免费的。
You may try this to check for errors instead of or in addition to checking for send()
true:
您可以尝试检查错误,而不是检查send() true:
if ( $mail->IsError() ) { //
echo ERROR;
}
else {
echo NO ERRORS;
}
//Try adding this too, for debugging:
$mail->SMTPDebug = 2; // enables SMTP debug information
Everything else in your code looks fine. We use PHPMailer a lot and never had any problems with it
代码中的其他内容看起来都很好。我们经常使用PHPMailer,从来没有遇到过任何问题
#5
1
The key may lie in the parts you have omitted. Is the domain of the sender of both emails the same? Otherwise the SMTP host may see this as a relay attempt. If you have access to the SMTP server logs, check these; they might offer a clue.
关键可能在于你漏掉的部分。这两封邮件的发件人的域相同吗?否则,SMTP主机可能会将此视为继电器尝试。如果您有访问SMTP服务器日志的权限,请检查这些日志;他们可能会提供一个线索。
Also, check what $mail->ErrorInfo
says... it might tell you what the problem is.
另外,检查$mail->ErrorInfo说什么…它可能会告诉你问题出在哪里。
#6
1
i personally would try to make small steps like sending same email.. so just clear recipients and try to send identical email (this code works for me). If this code passes you can continue to adding back your previous lines and debug where it fails
我个人会尝试做一些小步骤,比如发同样的邮件。所以,只需要清除收件人并尝试发送相同的电子邮件(此代码适用于我)。如果此代码通过,您可以继续添加以前的行并调试失败的地方。
and maybe $mail->ClearCustomHeaders();
doing problems
也许邮件- > 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
}
...
#7
1
Try with the following example.,
试试下面的例子。
<?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!";
}
?>
Note : Better you can make a multiple user email and name as an ARRAY, like
注意:更好的方法是,您可以创建多个用户电子邮件和名称作为数组,比如。
<?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);
}
?>
i think this may help you to resolve your problem.
我认为这可能有助于你解决你的问题。
#8
1
I think you've got organizational problems here.
我认为你们在组织上有问题。
I recommend:
我建议:
- Set your settings (SMTP, user, pass)
- 设置设置(SMTP, user, pass)
- Create new email object with info from an array holding messages and to addresses
- 创建新的电子邮件对象,包含来自包含消息和地址的数组的信息
- Send email
- 发送电子邮件
- Goto step 2
- 转到步骤2