phpmailer 不发送电子邮件到 gmail、yahoo、hotmail 或者这些阻止 phpmailer 发送的电子邮件
phpmailer not sending email to gmail,yahoo,hotmail or these are blocking email sent by phpmailer
我正在使用 PHPmailer 发送电子邮件
这是我使用过的代码:
$mail = new PHPMailer();
$subject = "test";
$to = "test_patel@yahoo.com"
$mail->SetFrom("PDSociety@aol.com","Punjab Dental Society");
$mail->AddReplyTo("PDSociety@aol.com", "Punjab Dental Society");
$mail->Subject = $subject;
$mail->MsgHTML($str);
$mail->AddAddress($to, "Punjab Dental Society");
if(!$mail->Send())
{
$err = "Mailer Error: " . $mail->ErrorInfo;
//echo $err;
} else {
$msg = "Message sent!";
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
如果我将电子邮件地址从 yahoo 更改为 gmail 或 hotmail,仍然无法发送电子邮件。
我通过回显错误进行了检查,但没有错误。
谁能解释一下这是什么问题?
您是否看过此处的 post:Using PHPMailer Results in many blocked emails?提问者通过更改电子邮件主题解决了问题:
Well I solved the issue; the code above was not the problem and works
great.
In my subject, I used a phrase regarding "verify your account
information" and that got it blocked on a few ISP's.
So the lesson is, your subject matters. I was looking at my php code
and my body content before I realized this.
电子邮件的内容及其主题可以使 ISP 禁止它。您可以尝试从收件箱中提取其中一封收到的电子邮件的内容,看看是否通过。
试试这个:
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->AddAddress($to['email'],$to['name']);
$mail->FromName = '';
$mail->Subject = $subject;
$mail->MsgHTML($message);
$send = true;
return $mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
如果有任何异常错误,它会帮助你。
PHPMailer 只涉及将邮件提交到您自己的邮件服务器,您在那里没有任何问题。之后,您的邮件服务器将负责发送它,因此您将在邮件服务器的日志中找到答案。
没有简单的方法可以确保邮件最终进入收件箱而不是垃圾邮件 - 如果有,垃圾邮件发送者就会使用它并且过滤将毫无用处。确保你的 DNS 能够前后解析,你有有效的 SPF 记录,你用 DKIM 签署你的消息(对雅虎来说尤其重要),最重要的是,你不会发送你的收件人认为是垃圾邮件的消息。
尝试各种方法后,我发现以下代码适用于几乎所有电子邮件提供商
$to['email'] = "recipients email address";
$to['name'] = "name";
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = 'xyz@domainname.com';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('xyz@domainname.com', 'any name');
$mail->AddAddress($to['email'],$to['name']);
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;
}
$mail->ClearAddresses();
需要相应地更改变量值。
希望这些可以帮助遇到 PHPmailer 问题的人
我正在使用 PHPmailer 发送电子邮件
这是我使用过的代码:
$mail = new PHPMailer();
$subject = "test";
$to = "test_patel@yahoo.com"
$mail->SetFrom("PDSociety@aol.com","Punjab Dental Society");
$mail->AddReplyTo("PDSociety@aol.com", "Punjab Dental Society");
$mail->Subject = $subject;
$mail->MsgHTML($str);
$mail->AddAddress($to, "Punjab Dental Society");
if(!$mail->Send())
{
$err = "Mailer Error: " . $mail->ErrorInfo;
//echo $err;
} else {
$msg = "Message sent!";
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
如果我将电子邮件地址从 yahoo 更改为 gmail 或 hotmail,仍然无法发送电子邮件。
我通过回显错误进行了检查,但没有错误。
谁能解释一下这是什么问题?
您是否看过此处的 post:Using PHPMailer Results in many blocked emails?提问者通过更改电子邮件主题解决了问题:
Well I solved the issue; the code above was not the problem and works great.
In my subject, I used a phrase regarding "verify your account information" and that got it blocked on a few ISP's.
So the lesson is, your subject matters. I was looking at my php code and my body content before I realized this.
电子邮件的内容及其主题可以使 ISP 禁止它。您可以尝试从收件箱中提取其中一封收到的电子邮件的内容,看看是否通过。
试试这个:
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->AddAddress($to['email'],$to['name']);
$mail->FromName = '';
$mail->Subject = $subject;
$mail->MsgHTML($message);
$send = true;
return $mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
如果有任何异常错误,它会帮助你。
PHPMailer 只涉及将邮件提交到您自己的邮件服务器,您在那里没有任何问题。之后,您的邮件服务器将负责发送它,因此您将在邮件服务器的日志中找到答案。
没有简单的方法可以确保邮件最终进入收件箱而不是垃圾邮件 - 如果有,垃圾邮件发送者就会使用它并且过滤将毫无用处。确保你的 DNS 能够前后解析,你有有效的 SPF 记录,你用 DKIM 签署你的消息(对雅虎来说尤其重要),最重要的是,你不会发送你的收件人认为是垃圾邮件的消息。
尝试各种方法后,我发现以下代码适用于几乎所有电子邮件提供商
$to['email'] = "recipients email address";
$to['name'] = "name";
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = 'xyz@domainname.com';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('xyz@domainname.com', 'any name');
$mail->AddAddress($to['email'],$to['name']);
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;
}
$mail->ClearAddresses();
需要相应地更改变量值。 希望这些可以帮助遇到 PHPmailer 问题的人