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';
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.