Can send mail through Usermin or GMAIL but not from PHP

Hi. I’ve created an email id 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: Host: 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->SMTPDebug = 2;
$mail->Host = “”;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘TLS’;
$mail->Port = 587;
$mail->Username = “info.domian”;
$mail->Password = ‘mypassword’;
$mail->setFrom(‘’, ‘Website Name’);
$mail->addReplyTo(‘’, ‘Website Name’);

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


Are you receiving an error?

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


Sorry I had missed your error message.

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

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

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

The tutorial over at suggests you need an autoload.php required.

And another (using TLS) over at

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

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

Did you make Gmail “less secure” ???

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

Or, instead of “less secure”, implement OAuth2:

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.

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.