0

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.

Sachin
  • 1,646
  • 3
  • 22
  • 59
  • Maybe try port 25 or 587. I had similiar issues with other smtp servers where on my local dev I used port 465 and it worked and on prod I had to use 25. This was not google smtp but may be the same issue here. – Code Spirit Dec 03 '22 at 14:23
  • Please re-read this: `I have already tried their host and port various combination and some other settings too.` – Sachin Dec 03 '22 at 16:40
  • Another thing, you should obscure your smtp log because it contains your base64 encoded credentials. – Code Spirit Dec 03 '22 at 19:22
  • Does this answer your question? [PHPMailer - SMTP ERROR: Password command failed when send mail from my server](https://stackoverflow.com/questions/21937586/phpmailer-smtp-error-password-command-failed-when-send-mail-from-my-server) – Ken Lee Dec 03 '22 at 21:01
  • make your smtp debug to 1 and you get more info regarding error $mail->SMTPDebug = 1; – Ariful Islam Dec 04 '22 at 13:31
  • For what it's worth, the gmail system (along with other mass email operations) can be super hard nosed in the way they block spam. It's possible some other GoDaddy customer on the same machine -- the same IP address -- as yours sent a bunch of messages that triggered their spam trap. This may have caused their system to block every connect() request from that machine. Consider using an email service provider. SendGrid has a generous free tier. – O. Jones Dec 04 '22 at 13:38

1 Answers1

0

I can't understand why this question is negatively marked. The people doing this could not even imagine that there could be some other potentially valid reason behind this issue.

Anyway, I've solved this issue on my own. SMTP services are not enabled by default on VPS, but only on dedicated servers. I enabled them and my PHPMailer is working.

Thanks to everyone here for helping me.

Sachin
  • 1,646
  • 3
  • 22
  • 59