在我工作的公司,我們使用Microsoft Exchange Server和Outlook Express發送和接收電子郵件。PHPMailer爲什麼我得到連接超時錯誤?
onriod我們使用交換應用程序如下訪問我們的郵件。
我嘗試使用下面的代碼在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
正如它所說 - 它無法連接到您的郵件服務器。這可能是因爲你的ISP阻止了出站SMTP。閱讀錯誤消息鏈接到的故障排除指南。 – Synchro
是的,我得到了,但如果出站SMTP被阻止,我怎麼能連接使用Android上的第三方應用程序? –
因爲它在您的服務器所在的網絡上被阻止,但不是您手機所在的網絡。這取決於網絡,而不是客戶端代碼。如果PHPMailer正在您的手機上運行,它會起作用。 – Synchro