2017-04-02 37 views
-2

在我工作的公司,我們使用Microsoft Exchange Server和Outlook Express發送和接收電子郵件。PHPMailer爲什麼我得到連接超時錯誤?

onriod我們使用交換應用程序如下訪問我們的郵件。

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('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
//$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
//$mail->addCC('[email protected]'); 
//$mail->addBCC('[email protected]'); 

//$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 Connection: opening to mail.dom-domain.com:587, timeout=300, options=array () 2017-04-02 13:14:48 Connection failed. Error #2: stream_socket_client(): unable to connect to mail.dom-domain.com:587 (Connection timed out) [/home/xxxxxxx/public_html/ml/PHPMailer/class.smtp.php line 294] 2017-04-02 13:14:48 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2017-04-02 13:14:48 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

+0

正如它所說 - 它無法連接到您的郵件服務器。這可能是因爲你的ISP阻止了出站SMTP。閱讀錯誤消息鏈接到的故障排除指南。 – Synchro

+0

是的,我得到了,但如果出站SMTP被阻止,我怎麼能連接使用Android上的第三方應用程序? –

+0

因爲它在您的服務器所在的網絡上被阻止,但不是您手機所在的網絡。這取決於網絡,而不是客戶端代碼。如果PHPMailer正在您的手機上運行,​​它會起作用。 – Synchro

回答

0

保持注意到在您的Android設備上,您大多使用通過端口443的Microsoft Active Sync。您不通過端口587使用本地SMTP連接(其中w應該通過IMAP/POP3使用)。對於使用MAPI或MAPI over HTTP/Outlook Anywhere的普通Outlook連接也是如此。兩者都不使用本地SMTP連接,可能是它沒有工作的原因。但是在你的GMail帳戶中,你主要使用IMAP,因爲這不是支持Microsoft Active Sync的Exchange Server。

因此,您的Exchange管理員可能無法爲Outlook用戶配置外部已通過身份驗證的連接的SMTP連接器,因爲您不需要這樣做,因此出於安全原因禁用了該連接。正如你沒有指定你是否是Exchange管理員,你正在使用哪個版本並不容易給你一個如何在這裏。因此,而不是說,你應該在這裏請按照下列HOWTO文檔從微軟:

如果地圖無法在Microsoft Exchange管理員,你可以嘗試通過在Microsoft Exchange發送電子郵件Web服務(請參閱here)。但是,如上所述,Exchange管理員可能會在此處運行特殊配置來保護環境。

相關問題