I've organized the code like this:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/Exception.php';
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/PHPMailer.php';
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/SMTP.php';
$mail = new PHPMailer(true);
try {
echo 'start';
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'hidden'; // SMTP username
$mail->Password = 'hidden'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('hidden', 'Mailer');
$mail->addAddress('hidden', 'Michael');
// Content
$mail->Subject = 'Test';
$mail->Body = 'Test';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
"Less Secure App" in Gmail is turned ON. Login and password are doublechecked by copying and pasting to the browser.
Exception:
start2020-12-11 16:36:00 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP c16sm931756lfb.236 - gsmtp
2020-12-11 16:36:00 CLIENT -> SERVER: EHLO psywomenandmen.ru
2020-12-11 16:36:00 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [5.101.156.177]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2020-12-11 16:36:00 CLIENT -> SERVER: STARTTLS
2020-12-11 16:36:00 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2020-12-11 16:36:00 CLIENT -> SERVER: EHLO psywomenandmen.ru
2020-12-11 16:36:00 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [5.101.156.177]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2020-12-11 16:36:00 CLIENT -> SERVER: AUTH LOGIN
2020-12-11 16:36:00 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-12-11 16:36:00 CLIENT -> SERVER: [credentials hidden]
2020-12-11 16:36:00 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-12-11 16:36:00 CLIENT -> SERVER: [credentials hidden]
2020-12-11 16:36:01 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 bXAEJKkJeqWCiVzTTlBWq9rxftBEamfSnaWIVJ0_dKDfgIuJ6a7XbSNz62WFwSuLLEQAO534-5.7.14 vcrBWQgPPNpki5WeHQlOd9wE2RNXirLYC1_og20m_xsWH4wka8pkDZJz0Iv-LySW>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 c16sm931756lfb.236 - gsmtp
2020-12-11 16:36:01 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 bXAEJKkJeqWCiVzTTlBWq9rxftBEamfSnaWIVJ0_dKDfgIuJ6a7XbSNz62WFwSuLLEQAO534-5.7.14 vcrBWQgPPNpki5WeHQlOd9wE2RNXirLYC1_og20m_xsWH4wka8pkDZJz0Iv-LySW>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 c16sm931756lfb.236 - gsmtp
SMTP Error: Could not authenticate.
2020-12-11 16:36:01 CLIENT -> SERVER: QUIT
2020-12-11 16:36:01 SERVER -> CLIENT: 221 2.0.0 closing connection c16sm931756lfb.236 - gsmtp
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
Did I do something wrong with ports and other options?
No, you did nothing wrong with ports and options, they're all fine. What you did wrong was not read the error message.
<https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv
534-5.7.14 bXAEJKkJeqWCiVzTTlBWq9rxftBEamfSnaWIVJ0_dKDfgIuJ6a7XbSNz62WFwSuLLEQAO
534-5.7.14 vcrBWQgPPNpki5WeHQlOd9wE2RNXirLYC1_og20m_xsWH4wka8pkDZJz0Iv-LySW>
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 c16sm931756lfb.236 - gsmtp
This provides a link to a page that tells you more, and also a straightforward instruction: "Please log in via your web browser and then try again". What that means is that you should log into gmail via your browser, and only then try running your script again.
There is a further step you might have to do involving gmail's unlock captcha page, but you'll find out about that by reading the PHPMailer troubleshooting guide that contains full details of this exact issue.