0

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
  • 13
  • 116
  • 190
RedXTech
  • 406
  • 2
  • 7
  • 17
  • 1
    Did you try commenting out '$mail->isSMTP()' as suggested here? http://stackoverflow.com/questions/18496650/smtp-connect-failed-message-was-not-sent-mailer-error-smtp-connect-failed – tim berspine Jul 07 '16 at 20:06
  • @timberspine I just did so, and it doesn't work. – RedXTech Jul 07 '16 at 20:09
  • When you turn on debugging '$mail->SMTPDebug = 1', what do you see? – tim berspine Jul 07 '16 at 20:13
  • 1
    SMTPDebug = 2 would be a more useful debugging level. There are plenty of questions on SO about PHPMailer and gmail accounts as well as PHPMailer and GoDaddy. I'm sure this question is a duplicate of one of them.... – Martin Jul 07 '16 at 20:15
  • @timberspine 2016-07-07 20:20:03 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-07-07 20:20:03 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting – RedXTech Jul 07 '16 at 20:20
  • @Martin check previous comment – RedXTech Jul 07 '16 at 20:20
  • 1
    Possible duplicate of [PHP on GoDaddy Linux Shared trying to send through GMAIL SMTP](http://stackoverflow.com/questions/5440026/php-on-godaddy-linux-shared-trying-to-send-through-gmail-smtp) – Synchro Jul 07 '16 at 21:03
  • thanks @tim berspine !! – vasmos Sep 19 '19 at 23:15

3 Answers3

5

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;
wrydere
  • 668
  • 8
  • 17
vignesh Subash
  • 2,577
  • 1
  • 11
  • 15
0

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.

Fencer04
  • 1,084
  • 1
  • 11
  • 17
0

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.

RedXTech
  • 406
  • 2
  • 7
  • 17