PHPMailer with GMail: SMTP Error

I use PHPMailer to send mail through GMail. The code I use is straight from the tutorial and it works fine on my laptop. However, testing this on a Windows 2003 Server - it always seems to return an SMPT error:

SMTP Error: Failed to connect to the SMTP host. Mailer error: SMTP error: it is possible not to connect to the SMTP host.

Here are the settings I use in PHPMailer:

include("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // use ssl $mail->Host = "smtp.gmail.com"; // GMAIL SMTP server $mail->Port = 465; // SMTP port used by GMAIL server 

Can I say with confidence that this is not a port problem, since I connect to another server on port 465 and send mail. If not, explain.

How can I solve this problem?

Thank you all for your help.

+4
source share
2 answers

First of all, note: Gmail uses TLS. I don't know if SSL will be used instead of TLS, but SSL is a precursor to TLS.

I recommend checking also its phpmailer configured to use gmail. PHPGMailer

+4
source

To use PHPMailer with gmail, do not use SSL / 465 (it has been deprecated since 1998), use TLS / 587, as Noctrine suggests, and here's how:

 include 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer; $mail->IsSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "tls://smtp.gmail.com"; // GMAIL SMTP server $mail->Port = 587; // SMTP port used by GMAIL server ... 

You must find what works.

+2
source

Source: https://habr.com/ru/post/1310256/


All Articles