Home > front end >  PHPMailer does NOT work on one of my GoDaddy servers - SMTP connect() failed
PHPMailer does NOT work on one of my GoDaddy servers - SMTP connect() failed

Time:12-03

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 = "[email protected]";
$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 = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]", "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:

2022-12-03 14:06:16 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => false, ),)
2022-12-03 14:06:16 Connection: opened
2022-12-03 14:06:16 SERVER -> CLIENT: 220-30.73.148.132.host.secureserver.net ESMTP Exim 4.95 #2 Sat, 03 Dec 2022 14:06:16  0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2022-12-03 14:06:16 CLIENT -> SERVER: EHLO domain.com
2022-12-03 14:06:16 SERVER -> CLIENT: 250-30.73.148.132.host.secureserver.net Hello domain.com [132.148.73.30]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPE_CONNECT250-AUTH PLAIN LOGIN250 HELP
2022-12-03 14:06:16 CLIENT -> SERVER: AUTH LOGIN
2022-12-03 14:06:16 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2022-12-03 14:06:16 CLIENT -> SERVER: bXNsLm1lYXN1cmVtZW50c3lzdGVtc0BnbWFpbC5jb20=
2022-12-03 14:06:16 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2022-12-03 14:06:16 CLIENT -> SERVER: cXJsamlvdmZ1anFkbWNlaw==
2022-12-03 14:06:18 SERVER -> CLIENT: 535 Incorrect authentication data
2022-12-03 14:06:18 SMTP ERROR: Password command failed: 535 Incorrect authentication data
SMTP Error: Could not authenticate.
2022-12-03 14:06:18 CLIENT -> SERVER: QUIT
2022-12-03 14:06:18 SERVER -> CLIENT: 221 30.73.148.132.host.secureserver.net closing connection
2022-12-03 14:06:18 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
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.

CodePudding user response:

It looks like the issue is with the authentication data being incorrect. The error message specifically mentions that the authentication data is incorrect: "535 Incorrect authentication data".

To fix this, you need to make sure that you are using the correct username and password for your Gmail account. In the code you provided, these values are specified in the following lines:

$mail->Username = "[email protected]";
$mail->Password = "password";

Make sure that the username and password you are using here are correct, and that they are the same as the ones you use to login to your Gmail account. If you are still having issues, you may want to try resetting your Gmail password and then using the new password in your code.

If you are still having trouble after checking the username and password, you may want to try enabling less secure apps for your Gmail account. You can do this by following the instructions here: https://support.google.com/accounts/answer/6010255?hl=en

After following these steps, your PHPMailer script should be able to authenticate successfully and send emails. Let me know if you have any other questions.

CodePudding user response:

There are a few potential reasons why the PHPMailer script might not be working on your GoDaddy server. Here are a few things you can try to troubleshoot the issue:

  1. Make sure that the PHPMailer library is installed and configured properly on your GoDaddy server. This includes ensuring that the correct paths to the PHPMailer files are specified in your PHP script, and that all required dependencies are installed and configured properly.

  2. Check the server logs for any errors or messages related to the PHPMailer script. This can help you identify any specific issues that might be preventing the script from working properly.

  3. Try using a different SMTP server to send the email. For example, instead of using Gmail as your SMTP server, you could try using a different server (e.g., Outlook, Yahoo, etc.) to see if that resolves the issue.

  4. Make sure that the PHP script has the necessary permissions to access the SMTP server and send emails. This can sometimes be an issue on shared hosting environments, where the server may have strict security settings that prevent certain PHP scripts from accessing certain resources.

  5. If you're still having trouble, you may want to try contacting GoDaddy support for further assistance. They may be able to provide more specific guidance on why the PHPMailer script is not working on your server, and help you troubleshoot the issue.

  • Related