Search code examples
phpemailphpmailer

PHPMailer SMTP Connection Failed - GoDaddy


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?


Solution

  • 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;