我正在尝试设置 PHPMailer,以便我们的一位客户能够从他们自己的帐户中自动生成电子邮件。我登录了他们的Of fice 365帐户,发现PHPMailer所需的设置是:
Host: smtp.off ice365.com Port: 587 Auth: tls
我已将这些设置应用于 PHPMailer,但是没有发送电子邮件(我调用的函数适用于我们自己的邮件,该邮件是从外部服务器(不是服务网页的服务器)发送的)。
"host" => "smtp.of fice365.com", "port" => 587, "auth" => true, "secure" => "tls", "username" => "clientemail@off ice365.com", "password" => "clientpass", "to" => "myemail", "from" => "clientemail@of fice365.com", "fromname" => "clientname", "subject" => $subject, "body" => $body, "altbody" => $body, "message" => "", "debug" => false
有谁知道PHPMailer通过smtp.offi ce365.com发送需要什么设置?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
@nitin 的代码对我不起作用,因为它在 SMTPSecure 参数中缺少“tls”。
这是一个工作版本。我还添加了两行注释掉的行,您可以在出现问题时使用它们。
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 in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; }