try {
$mail = new PHPMailer();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'amtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'ali@gmail.com';
$mail->Password = '*************';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('ali@gmail.com');
$mail->addAddress('recipient@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Subject';
$mail->Body = 'This is the HTML message body';
if ($mail->send()) {
echo 'Message has been sent.';
} else {
echo 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}