Phpmailer smtp error could not authenticate

Sending a mail through PHPMailer is often scripted via PHP if you intend to send email notifications when new comments are recieved on your wordpress blog, or when the server is overloaded with high CPU spikes (via uptime showing load-averages in the last 1, 5 and 15 minutes).

You are reading: Phpmailer smtp error could not authenticate

If you are using Gmail, most likely is that the Google GMail will report back with a error: Could Not Authenticate even you have typed in the correct password for your Gmail account.

Putting your account password directly somewhere in your script is not a good idea, and the correct way to solve this problem and avoid leaking your main account password is to use the App Password. Alternatively, you can customize your security settings for less-secured applications – which it may not work as it is just a PHP script here.

See also: How To Tell If Your Email Address Is Blocked You On Gmail, How To Tell If Your Email Address Is Blocked

App Password can be set separately for each individual application and you can also re-generate one if one is compromised.

You would need to visit Google Security Dashboard: https://myaccount.google.com/security

*

google-app-passwords-security

Then, add a App Password (Select GMail, and Others – give the App a Name) – which can be used in the PHPMailer – in case this password is leaked, you can always delete it and regenerate a new one.

See Also:  19 Powerful B2B Direct Mail Examples [with an Insane ROI] - Postary

See also: How To Embed Gifs In Gmail, Insert An Animated Gif Into An Email

*

google-app-passwords

Then, the following PHPMailer sample code should be used to do the email testing.

#!/usr/bin/phpIsHTML(true); $mailer->IsSMTP(); $mailer->From = $username; $mailer->FromName = $username; $mailer->ClearAllRecipients(); $mailer->AddAddress(“Recipent Email Address”, “Recipent”); $mailer->Subject = “Subject “; $mailer->Body = “Hello, time is: “. date(“Y-m-d h:i:s”); $mailer->SMTPAuth = true; // enable SMTP authentication $mailer->SMTPSecure = $secure; // sets the prefix to the servier $mailer->Host = $host; // sets GMAIL as the SMTP server $mailer->Port = $port; // set the SMTP port for the GMAIL server $mailer->Username = $username; // GMAIL username $mailer->Password = $password; // GMAIL password $result = $mailer->Send(); echo “Mail sentn”; } catch (Exception $e) { echo “Message could not be sent. Mailer Error: “; var_dump($e); }
Remember, you would also need to update the Email settings in WordPress Plugin – SMTP. And make sure you have the following credentials for Gmail updated in the wp-settings.php
Categories: Mail


Leave a Reply

Your email address will not be published. Required fields are marked *