配置 PHPMailer 以使用 Off ice365 SMTP
P粉510127741
P粉510127741 2023-10-16 10:39:47
[PHP讨论组]

我正在尝试设置 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发送需要什么设置?

P粉510127741
P粉510127741

全部回复(1)
P粉395056196

@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';
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号