Php 您如何使用outlook业务网络向同一公司的域发送电子邮件?
我所在的公司有防火墙、代理和域,我们的电子邮件如下:persona@company.co,我们使用outlook exchange 我试图发送电子邮件,但它给我一个身份验证错误,我不知道是防火墙阻止它或代理 我想在公司网络中拥有Exchange帐户的用户之间使用phpmailer库发送电子邮件 我的代码:Php 您如何使用outlook业务网络向同一公司的域发送电子邮件?,php,phpmailer,Php,Phpmailer,我所在的公司有防火墙、代理和域,我们的电子邮件如下:persona@company.co,我们使用outlook exchange 我试图发送电子邮件,但它给我一个身份验证错误,我不知道是防火墙阻止它或代理 我想在公司网络中拥有Exchange帐户的用户之间使用phpmailer库发送电子邮件 我的代码: <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'Excepti
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.office365.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'me@business.co'; // SMTP username
$mail->Password = '*********'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('email@from.com', 'Angel');
$mail->addAddress('******@business.co'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
这里没有足够的信息。请设置SMTPDebug=2
并将输出添加到您的问题中。此处的信息:2020-01-08 11:55:22 SMTP错误:无法连接到服务器:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应而建立的连接失败。(10060)SMTP连接()失败。无法发送消息。邮件程序错误:SMTP连接()失败。这是超时,不是身份验证失败。您的ISP可能会阻止出站SMTP。使用错误消息中的“疑难解答指南”中的建议进行诊断。好的,我想尝试我的个人outlook帐户以了解更多信息。开始发送电子邮件SMTP地址是:SMTP.office365.com端口:587 SMTPSecure:STARTTLS是吗?好的,看起来可能是您的凭据有误,或者您的帐户未配置为允许使用这些凭据发送SMTP-因此可能与您的脚本无关,而与outlook帐户有关。