PHPMailer with Office365

Posted under » PHP on 1 May 2020

You should install by composer. Otherwise you will not get the vendor directory structure for this tutorial.


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '/var/www/site/vendor/phpmailer/phpmailer/src/Exception.php';
require '/var/www/site/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require '/var/www/site/vendor/phpmailer/phpmailer/src/SMTP.php';

$mail = new PHPMailer(true); // instantiate 1st
$mail->Host = "";
$mail->Port     = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = 'MrLK1sUgly';
$mail->SetFrom('', 'FromEmail');

//From email address and name
$mail->FromName = "Bill Gates";

//To address and name
$mail->addAddress("", "Brad Pitt");

//Address to which recipient will reply
// $mail->addReplyTo("", "Reply");

//CC and BCC
// $mail->addCC("");
// $mail->addBCC("");

//Send HTML or Plain Text email

$mail->Subject = "Subject Text";
$mail->Body = "Mail body in HTML";
$mail->AltBody = "This is the plain text version of the email content";

    echo "Mailer Error: " . $mail->ErrorInfo;
    echo "Message has been sent successfully";


web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data