Setting up PHPMailer with Office365 SMTP
@nitin's code was not working for me, as it was missing 'tls' in the SMTPSecure param.
Here is a working version. I've also added two commented out lines, which you can use in case something is not working.
<?php
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'somebody@somewhere.com';
$mail->Password = 'YourPassword';
$mail->SetFrom('somebody@somewhere.com', 'FromEmail');
$mail->addAddress('recipient@domain.com', 'ToEmail');
//$mail->SMTPDebug = 3;
//$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo';
$mail->IsHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Speed up PHPmailer with office 365 smtp
Thanks for the help,
To get over the problem i decided to store the email into a database.
Every 2 minutes i then run a cron job to clear the mail queue and send using the exchange smtp
If it take 10-12 seconds behind the scenes it has not ruined my customer experience.
Related Topics
The Behaviour of the or Operator in PHP
Cannot Set Date.Timezone in PHP.Ini File
How to Insert JSON Array into MySQL Database
Composer:How to Add a Dependency Without Network Connection
Error Starting Userland Proxy: Listen Tcp 0.0.0.0:3306: Bind: Address Already in Use
Datetime Now PHP MySQL (+ Pdo Variant)
PHP Prepared Statements and Transactions in a Loop
How to Rename a Filename After Uploading with PHP
PHP Class: Global Variable as Property in Class
PHP - Swiftmailer Using Starttls and Self Signed Certificates
Make Woocommerce Checkout Phone Field Optional Based on Shipping Country
Codeigniter Compatibility with PHP Version
Doctrine2 - "Class" Is Not a Valid Entity or Mapped Super Class
Php: $_Server Variables: $_Server['Http_Host'] VS $_Server['Server_Name']
Force Logout Users If Users Are Inactive for a Certain Period of Time
Can One Modify the Templates Created by Artisan Migrate Command
Changes to Upload_Max_Filesize in Ubuntu PHP.Ini Will Not Take Effect