天天看點

php office365 發郵件,PHPMailer通過Gmail和Office365的SMTP賬号發送郵件設定

以下測試可用。

Gmail

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->SMTPAuth = true;

//主要差別

$mail->Port = 25;

$mail->Host = "ssl://smtp.gmail.com:465";

$mail->Username = "[email protected]";

$mail->Password = "xxxxxxx";

$mail->From = "[email protected]";

$mail->FromName = "Someone";

$mail->CharSet = "utf-8";

$mail->AddAddress ( "[email protected]", "[email protected]" );

$mail->IsHTML (  true  );

$mail->Subject = "subject";

$mail->Body = "body";

$mail->AltBody = "text/html";

$mail->Send ();

Office 365

$mail = new PHPMailer();    $mail->IsSMTP(); $mail->SMTPAuth = true;  //主要差別 $mail->Port = 587;  $mail->Host = "smtp.office365.com"; $mail->Username = "[email protected]";     $mail->Password = "xxxx"; $mail->From = "[email protected]";  $mail->SMTPSecure = "tls"; $mail->FromName = "Someone"; $mail->CharSet = "utf-8"; $mail->AddAddress ( "[email protected]", "[email protected]" );  $mail->IsHTML (  true  );  $mail->Subject = "subject";  $mail->Body = "body";   $mail->AltBody = "text/html";   $mail->Send ();