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

人走茶凉 提交于 2019-12-13 16:12:30

问题


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

Error Message:

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

Php Code:

<?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.';
}

?>

Thanks.

Update:

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 ?


回答1:


There could be a number of reasons for this:

  • 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

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.

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



来源:https://stackoverflow.com/questions/21372975/message-was-not-sent-mailer-error-smtp-connect-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!