邮件未发送.邮件错误:SMTP connect()失败 [英] Message was not sent.Mailer error: SMTP connect() failed

查看:129
本文介绍了邮件未发送.邮件错误:SMTP connect()失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Php的新手,找到了一个Php mailer类来发送电子邮件,但出现以下错误.

I'm new in Php and find a Php mailer class to send email but getting following error.

错误消息:

Message was not sent.Mailer error: SMTP connect() failed. 

Php代码:

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.impeccableplus.com"; // SMTP server

$mail->From     = "from@example.com";
$mail->AddAddress("email@gmail.com");

$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

?>

谢谢.

更新:

我只是更改主机名= localhost.现在,它已成功发送了电子邮件,但问题是,它在垃圾邮件文件夹中显示了该邮件.为什么?

I just change the host name = localhost. Now it's successfully sent email but problem is, It's showing the mail in spam folder. Why ?

推荐答案

可能有多种原因:

  • 您的SMTP服务器smtp.impeccableplus.com可能已被列入黑名单.您可以检查您的SMTP服务器是否已被列入黑名单
  • from address可能被视为垃圾邮件,尤其是如果您使用的是from@example.com
  • 某些邮件客户端(例如Gmail)不喜欢您实际上是从某人的地址发送"电子邮件的事实
  • 以及其他20多个原因
  • Your SMTP server smtp.impeccableplus.com could be blacklisted. You can check if your SMTP server is being blacklisted
  • The from address could be regarded as spammy, especially if you're using from@example.com
  • Some mail clients (such as Gmail) do not like the fact that you are sending an email "from" someone else's address if it really didn't originate from that address
  • and possibly 20+ other reasons

您应该考虑为发送电子邮件的电子邮件地址设置 SPF DKIM .阅读.通过设置SPF和DKIM,您实质上是在对电子邮件进行身份验证,从而大大改善了邮件的传递.

You should consider setting up SPF and DKIM for your email address that you are sending emails from. Read this and this. By Setting up SPF and DKIM, you are essentially authenticating the email which considerably improves mail delivery.

或者,如果您确实遇到困难,请考虑使用邮件传递API,例如 Sendgrid .

Alternatively, if you really get stuck, consider using a mail delivery API such as Sendgrid.

这篇关于邮件未发送.邮件错误:SMTP connect()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆