Can send mail through Usermin or GMAIL but not from PHP

13 posts / 0 new
Last post
#1 Sat, 04/07/2018 - 06:24
Vipul.K

Can send mail through Usermin or GMAIL but not from PHP

Hi. I've created an email id info@domain.com and I'm able to send and receive mails through this id if I use Usermin. I've also used following settings to add this id to GMAIL (as sender) and I'm able to send mails through GMAIL as well.

Email: info@domian.com
Host: mail.domian.com
Username: info.domian
Password: **My password**
Port 587 (tls)

When I used PHPMailer in my website with following settings. I get an error that says 'Failed to connect to SMTP server'

$mail = new PHPMailer;

  $mail->isSMTP();
  $mail->SMTPDebug = 2;
  $mail->Host = "mail.domian.com";
  $mail->SMTPAuth = true;
  $mail->SMTPSecure = 'TLS';
  $mail->Port = 587;
  $mail->Username = "info.domian";
  $mail->Password = 'mypassword';
  $mail->setFrom('info@domian.com', 'Website Name');
  $mail->addReplyTo('info@domian.com', 'Website Name');

I've also tried Telnet to ping the host and that works too. I don't know what's the problem here.

Sat, 04/07/2018 - 15:02
tpnsolutions
tpnsolutions's picture

Hi,

Are you receiving an error?

Best Regards,
Peter Knowles | TPN Solutions
Email: pknowles@tpnsolutions.com | Skype: tpnassist
Sun, 04/08/2018 - 05:50
Vipul.K

Like I said, the error I get is 'Failed to connect to SMTP server'

Sun, 04/08/2018 - 13:14
tpnsolutions
tpnsolutions's picture

Hi,

Sorry I had missed your error message.

Try removing the line $mail->SMTPSecure = 'TLS' and see if you can connect without the TLS option.

Best Regards,
Peter Knowles | TPN Solutions
Email: pknowles@tpnsolutions.com | Skype: tpnassist
Mon, 04/09/2018 - 00:07
Vipul.K

I don't get emails after removing that line. And I get the same error as before.

Wed, 04/11/2018 - 23:40
Vipul.K

Has anyone done this before? What were the settings you used?

Thu, 04/12/2018 - 11:13
jimdunn

The tutorial over at https://github.com/PHPMailer/PHPMailer/wiki/Tutorial suggests you need an autoload.php required.

Thu, 04/12/2018 - 11:40
jimdunn
Fri, 04/13/2018 - 06:41
Vipul.K

I know how to use phpmailer I need settings for virtualmin email. I can send emails through a gmail id just fine.

Thu, 11/15/2018 - 09:28
Vipul.K

I would like to draw attention of Virtualmin engineers. Does anyone use phpmailer? What settings do you use? I need to use SMTP.

Wed, 11/21/2018 - 09:41
jimdunn

Did you make Gmail "less secure" ???

https://github.com/matomo-org/matomo/issues/8613
https://www.saleshandy.com/smtp/gmail-smtp-settings/


And, be sure you're using require_once(‘PHPMailerAutoload.php’); instead of require_once(‘class.phpmailer.php’);

Or, instead of "less secure", implement OAuth2:

https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

Thu, 11/22/2018 - 03:15
Vipul.K

Hi Jim, the error I'm getting is "Failed to connect to SMTP server". It has nothing to do with google. Thanks for your effort though.

Tue, 07/30/2019 - 00:29
markfilan

To resolve this issue, log in to your Gmail account through a web browser and enable access through less secure apps . Less secure apps can make your account more vulnerable, Google will automatically turn this setting off if it's not being used. However, bypass this security setting with a configuration tweak within your Google Email Account .

How more secure app help to protect your account?

  • Which level of access you're giving the client before you connect your Account.

  • Client access only a relevant part of your Account, like your email or calendar.

  • Connect your Google Account to the client without exposing your password.

    • Disconnect your Google Account from the client at any time.
Topic locked