PHPMailer为什么我得到连接超时错误?

时间:2017-04-02 13:24:08

标签: php exchange-server phpmailer

在我工作的公司中,我们使用microsoft exchange server和ofcourse ms outlook来发送和接收电子邮件。

on andriod我们使用交换应用程序如下来访问我们的邮件。

enter image description here

我正在尝试使用以下代码在PHP中发送电子邮件:

 require 'PHPMailer/PHPMailerAutoload.php';

 $mail = new PHPMailer;

 $mail->SMTPDebug = 3;                               // Enable verbose debug output

 $mail->isSMTP();                                      // Set mailer to use SMTP
 $mail->Host = 'mail.dom-domain.com';  // Specify main and backup SMTP servers
 $mail->SMTPAuth = true;                               // Enable SMTP authentication
 $mail->Username = 'username';                 // SMTP username
 $mail->Password = 'password123';                           // SMTP password
 $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
 $mail->Port = 587;                                    // TCP port to connect to

 $mail->setFrom('username@dom-domain.com', 'Mailer');
 $mail->addAddress('recname@yahoo.com', 'Joe User');     // Add a recipient
 //$mail->addAddress('ellen@example.com');               // Name is optional
 $mail->addReplyTo('username@dom-domain.com', 'Information');
 //$mail->addCC('cc@example.com');
 //$mail->addBCC('bcc@example.com');

 //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
 //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
 $mail->isHTML(true);                                  // Set email format to HTML

 $mail->Subject = 'Here is the subject tls587';
 $mail->Body    = 'This is the HTML message body tls587 <b>in bold!</b>';
 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients tls587';

 if(!$mail->send()) {
     echo 'Message could not be sent.';
     echo 'Mailer Error: ' . $mail->ErrorInfo;
 } else {
     echo 'Message has been sent';
 }

但页面加载很多,我收到此错误:

  

2017-04-02 13:13:45连接:打开mail.dom-domain.com:587,timeout = 300,options = array()2017-04-02 13:14:48连接失败。错误#2:stream_socket_client():无法连接到mail.dom-domain.com:587(连接超时)[/home/xxxxxxx/public_html/ml/PHPMailer/class.smtp.php第294行] 2017-04- 02 13:14:48 SMTP错误:无法连接到服务器:连接超时(110)2017-04-02 13:14:48 SMTP连接()失败。无法发送https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息.Mailer错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

1 个答案:

答案 0 :(得分:0)

请注意,在您的Android设备上,您通常通过端口443使用Microsoft Active Sync。您不要通过端口587(可通过IMAP / POP3使用)使用本机SMTP连接。对于使用MAPI或MAPI over HTTP / Outlook Anywhere的普通Outlook连接也是如此。两者都不使用本地SMTP连接,这可能是它无法正常工作的原因。但是您的GMail帐户主要使用IMAP,因为这不是支持Microsoft Active Sync的Exchange Server。

因此,您的Exchange管理员可能没有为Outlook用户配置SMTP Connector for external Authenticated connections,因为在您的情况下不需要这样做,因此出于安全原因而禁用。由于您没有指定您是Exchange管理员以及您使用的是哪个版本,因此不容易在此处为您提供方法。所以,不要这样,你应该从微软这里听到这些方法:

如果您不是Microsoft Exchange管理员,可以尝试通过Microsoft Exchange Web服务发送电子邮件(请参阅here)。但是,如上所述,Exchange管理员可能会在此处运行特殊配置以保护环境。

相关问题