Skip to content
Advertisement

Sending a mail using PHPMailer with Gmail Account

I am trying to send an email from my website using the PHPMailer library. All I did so for was:

  1. I downloaded PHPMailer 5.2-stable from this link.

  2. I uploaded the following files on my hosting: class.phpmailer.php, class.smtp.php and PHPMailerAutoload.php

  3. Then I created a file name contact.php and wrote the following code in it:

    JavaScript

But after running this file, I get the following error:

2021-06-25 11:44:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed.

I tried several emails including and email address directly made from my hosting service, a Gmail account and a Google Workspace email (Formerly called, G suit). All of the failed producing the mentioned error.

Finally, I think it is worth to mention that my hosting service does not support PHP’s mail() function and that’s why I needed to use SMTP.

Update: After contacting the host and trying a lot, while I am sure that I enter the correct username and password, I get the following error:

JavaScript

Advertisement

Answer

  1. Make sure that “less secure app access” setting is turned on for your account. https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cif-less-secure-app-access-is-on-for-your-account

  2. Secondly make sure that your host allows to use outgoing port 578, or you can even request them to enable outgoing port.

  3. Try using ssl instead of tls, which is more secure and reliable.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement