On one of of my GoDaddy servers, the PHPMailer does NOT work. While the same script does work pretty fine on local as well as on another GoDaddy server.
I'm using following script:
<?php
$to = "username@gmail.com";
$subject = "Test Subject";
$message = "Test email message";
require("PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->SMTPOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => false
)
);
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "username@gmail.com";
$mail->Password = "password";
$mail->SetFrom("username@gmail.com", "Website Admin");
$mail->AddAddress($to, "Website Admin");
$mail->Subject = $subject;
$mail->Body = "<html><body style='font-family:Arial, Helvetica, sans-serif;'>";
$mail->Body .= "<table>";
$mail->Body .= "<tr><th>Email:</th><td>$to</td></tr>";
$mail->Body .= "<tr><th>Message:</th><td>$message</td></tr>";
$mail->Body .= "</table>";
$mail->Body .= "</body></html>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients.";
$mail->WordWrap = 70;
if($mail->Send())
{
echo "Mail sent";
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
It gives me following error on GoDaddy:
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I'm using PHPMailer version 5.2.27.
I'm using app password for gmail account.
If the script was buggy then how it could even work in another areas? How to fix it to work on that GoDaddy server too?
I have already tried their host and port various combination and some other settings too.