2017-07-13 75 views

回答

-1

您可以使用下面的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 = '[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 '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=tsl 

欲瞭解更多詳細信息,您可以參考this link

希望這會幫助你。

相關問題