Phpmailer smtp error could not authenticate

Sending a mail through PHPMailer is often scripted via PHPhường if you intover khổng lồ send email notifications when new comments are recieved on your wordpress blog, or when the VPS is overloaded with high CPU spikes (via uptime showing load-averages in the last 1, 5 và 15 minutes).

Bạn đang xem: Phpmailer smtp error could not authenticate

If you are using Gmail, most likely is that the Google GMail will report baông xã with a error: Could Not Authenticate even you have sầu typed in the correct password for your Gmail tài khoản.

Putting your tài khoản password directly somewhere in your script is not a good idea, & the correct way to solve sầu this problem và avoid leaking your main account password is lớn 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.

Xem thêm: 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 và you can also re-generate one if one is compromised.

You would need lớn visit Google Security Dashboard:



Then, add a App Password (Select GMail, & 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.

Xem thêm:


Then, the following PHPMailer sample code should be used lớn bởi vì the tin nhắn testing.

#!/usr/bin/phpIsHTML(true); $mailer->IsSMTP(); $mailer->From = $username; $mailer->FromName = $username; $mailer->ClearAllRecipients(); $mailer->AddAddress("Recipent E-Mail 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 lớn the servier $mailer->Host = $host; // sets GMAIL as the SMTP VPS $mailer->Port = $port; // set the SMTPhường port for the GMAIL hệ thống $mailer->Username = $username; // GMAIL username $mailer->Password = $password; // GMAIL password $result = $mailer->Send(); emang lại "Mail sent "; } catch (Exception $e) eđến "Message could not be sent. Mailer Error: "; var_dump($e);
Rethành viên, you would also need khổng lồ update the Thư điện tử settings in WordPress Plugin – SMTPhường. And make sure you have the following credentials for Gmail updated in the wp-settings.php

Chuyên mục: Mail