Olá,
Pelo que notei, não está com problema, apenas com dúvida de como fazer!
Olhe os exemplos na documentação: PHPMailer/examples
Exemplo SMTP: sendmail.php
<?php
/**
* This example shows sending a message using a local sendmail binary.
*/
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
require '../vendor/autoload.php';
//CreatePassing a`true` newenables PHPMailer instanceexceptions
$mail = new PHPMailer;
// Set PHPMailer to use();
the sendmail transport
$mail->isSendmail>isSMTP();
//Set who the message is$mail->Host to= be'smtp.example.com';
$mail->SMTPAuth sent= fromtrue;
$mail->setFrom('[email protected]',>Port 'First= Last');25;
//Set an$mail->Username alternative= reply'[email protected]';
$mail-to>Password address= 'yourpassword';
$mail->addReplyTo>setFrom('replyto@example'list@example.com', 'First'List Last'manager');
//Set who the message is to be sent to
$mail->addAddress>addReplyTo('whoto@example'list@example.com', 'John'List Doe'manager');
//Set the subject line
$mail->Subject = 'PHPMailer sendmail test';
//Read an HTML message body from an external file, convertSimple referenceddatabase imagesmailing tolist embedded,test';
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), __DIR__$body);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is'To aview plain-textthe message, body';
//Attachplease use an imageHTML filecompatible email viewer!';
$mail->addAttachment>addAddress('images/phpmailer_mini.png');
//send the message$email, check for errors$name);
if (!$mail->send()) {
echo 'Mailer Error: '. $mail->ErrorInfo;
}; else// {
TRATE AQUI PARA VER echoSE 'MessageENVIOU sent!';
}MESMO