只是想知道如何使用 laravel 中集成的 Office365 发送电子邮件。
先谢谢你们了。
最佳答案
您可以使用下面的php代码使用Office365发送电子邮件
<?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 'Email could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Email has been sent.';
}
如果出现任何错误,您可以取消注释代码。
您还可以使用 Laravel 中的 Swift Mailer 库来发送电子邮件。 .env
文件应默认包含以下值:
MAIL_DRIVER=null
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
这些是默认值,您需要将其替换为您的 Office365 详细信息,如下所示:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=Office365AccountEmail
MAIL_PASSWORD=Office365AccountPassword
MAIL_ENCRYPTION=tls
更多详情可以引用this link
希望这对您有帮助。
关于php - 使用 Laravel 中集成的 Office365 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45080419/