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 ();

你可能感兴趣的:(PHP)