0

I just registered a domain via gsuite/gmail to use this as a new mailserver domain for my php mailer.

Now I read through most related topics and adapted the hints, but I still receive the error message:

Message could not be sent.

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Here is my code:

$mail->Subject = "Tutor found for help";    

//From email address and name
$mail->setFrom('frank@xxx.net', 'xxx.net');

$mail->addAddress("$clientmail", "$clientname");
//$mail->addAddress("nachhilfeanfrage@xxx.net", "xxx.net");

$mail->addReplyTo('frank@xxx.net', 'xxx.net');

$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2;  // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;  // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled required for GMail
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;    // Port for TLS Gmail
$mail->Username = 'xx';   // SMTP username
$mail->Password = 'xx';     

$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
Franky2207
  • 163
  • 2
  • 19

2 Answers2

2

This is possible duplicate of Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?

Probably you didn't allow for less secured apps in Gmail account security dashboard.

IT goldman
  • 14,885
  • 2
  • 14
  • 28
1

Before sending emails using the Gmail's SMTP Server, you to make some of the security and permission level settings under your Google Account Security Settings.

Make sure that 2-Step-Verification is disabled.

Turn ON the "Less Secure App" access or click https://myaccount.google.com/u/0/lesssecureapps.

If 2-step-verification is enabled, then you will have to create app password for your application or device.

For security measures, Google may require you to complete this additional step while signing-in. Click here to allow access to your Google account using the new device/app.

Note: It may take an hour or more to reflect any security changes

Remzi
  • 9
  • 2