PHPMailer SMTP Connection Failed - GoDaddy

喜夏-厌秋 提交于 2019-12-12 03:43:47

问题


I am working on a website, and in it there is a form that is used to send email through gmail with PHPMailer.

I have it all set up correctly, because it works on my AWS EC2 server. However, when I use the exact same setup on a GoDaddy hosting plan, it doesn't work (yes, I changed 'require' paths).

I am getting this error:

Mailer Error: SMTP connect() failed.

Here is my code:

$mail = new PHPMailer;

$mail->SMTPDebug = 0;

$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "**********@gmail.com";
$mail->Password = "*************";
$mail->SMTPSecure = "tls";
$mail->Port = 587;

$mail->setFrom("**********@gmail.com", "Red's Mailer");
$mail->addAddress("*********@shaw.ca", "Name");

$mail->isHTML = true;

$mail->Subject = "New Submission From " . $name;
$mail->Body = $html_msg;
$mail->AltBody = $alt_msg;

Any ideas on the problem?


回答1:


GoDaddy mail server does not support any email containing "FROM" header entry of aol, gmail, hotmail, yahoo, live, aim or msn.

If you are using linux cPanel hosting plan then you do need to change few lines in your php code and it will work!

$mail = new PHPMailer;
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->ssl = false;
$mail->authentication = false;
$mail->addAddress("*********@shaw.ca", "Name");
$mail->isHTML = true;
$mail->Subject = "New Submission From " . $name;
$mail->Body = $html_msg;
$mail->AltBody = $alt_msg;



回答2:


I had similar issues. GoDaddy does not allow SMTP outside using the emails with your domain. If you contact support your should get the same answer.




回答3:


I have found out why this isn't working - GoDaddy, for some reason doesn't like letting their clients using anyone else's SMTP servers, so you either have to use the email hosting provided by cPanel, which is extremely slow and inneficient.

What I've done instead is have the script hosted on an AWS ec2 instance and have the forms for the script post to that instead.



来源:https://stackoverflow.com/questions/38254105/phpmailer-smtp-connection-failed-godaddy

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