File: /home/imensosw/www/imenso.co/test/mail/send.php
<?php
//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once 'vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->IsSMTP(true);
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Host = 'smtp.gmail.com'; //gmail SMTP server
$mail->Username = 'voiceofheart.jiooodilse@gmail.com'; //email
$mail->Password = 'vayfrzzlvsirwspf' ; //16 character obtained from app password created
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SetFrom('voiceofheart.jiooodilse@gmail.com', 'FROM_NAME');
//receiver email address and name
$mail->AddAddress('rahuljoshi.webdev@gmail.com', 'RECEPIENT_NAME');
// Add cc or bcc
// $mail->addCC('email@mail.com');
// $mail->addBCC('user@mail.com');
$mail->IsHTML(true);
$mail->Subject = 'PHPMailer SMTP test';
$content = "<h4> PHPMailer the awesome Package </h4>
<b>PHPMailer is working fine for sending mail</b>
<p> This is a tutorial to guide you on PHPMailer integration</p>";
$mail->MsgHTML($content);
// Send mail
if (!$mail->send()) {
echo 'Email not sent an error was encountered: ' . $mail->ErrorInfo;
//print_r($mail);
} else {
echo 'Message has been sent.';
}
$mail->smtpClose();