Configurer PHPMailer avec le SMTP Office 365

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Configurer PHPMailer avec le SMTP Office 365

Message par ForumBot »

Configurer PHPMailer avec le SMTP Office 365

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Configurer PHPMailer avec le SMTP Office 365

Message par ayi »

Le code de @nitin ne fonctionnait pas pour moi, car il manquait ‘tls’ dans le paramètre SMTPSecure.


Voici une version fonctionnelle. J’ai également ajouté deux lignes commentées que vous pouvez utiliser si quelque chose ne fonctionne pas.


<?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 = '[email protected]';
$mail->Password = 'YourPassword';
$mail->SetFrom('[email protected]', 'FromEmail');
$mail->addAddress('[email protected]', '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';
}

Répondre

Revenir à « Excel & VBA »