Esse exemplo está funcionando.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '
[email protected]';
$mail->Password = '_password_';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('
[email protected]', 'Admin');
$mail->addAddress('
[email protected]', 'Recipient1');
$mail->addAddress('
[email protected]');
$mail->addReplyTo('
[email protected]', 'noreply');
$mail->addCC('
[email protected]');
$mail->addBCC('
[email protected]');
//Attachments
$mail->addAttachment('/backup/myfile.tar.gz');
//Content
$mail->isHTML(true);
$mail->Subject = 'Test Mail Subject!';
$mail->Body = 'This is SMTP Email Test';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
fonte: https://tecadmin.net/send-email-using-php-script-from-smtp/