我想使用phpmailer向office365发送邮件,但它不发送并给我一个connect()错误 这是我的代码:
我在实际代码中使用的电子邮件和密码非常有用
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.office365.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
// or try these settings (worked on XAMPP and WAMP):
// $mail->Port = 587;
// $mail->SMTPSecure = 'tls';
$mail->Username = "email";
$mail->Password = "password";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->Username = "mail@gmail.com";
$mail->FromName = "Your Name";
$mail->addAddress("abc@gmail.com","User 1");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send()) {
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
输出
未发送消息 PHPMailer错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting