简体   繁体   中英

PHPmailer smtp to exchange - “DATA END command failed” after 30s (but no timeout)

I am using the latest PHPMailer 5.2.24 (problem is the same with older versions) on PHP 7.0.

Sending mails via SMTP with an Exchange 2016. About 95% of the mails work like expected, but whenever the 250 response from Exchange to the final DATA END command lasts longer than 30sec the stream seems to abort.

Timeout in PHPMailer is set to 300 and in the logs i can confirm that timeout is not the Problem here.

In fact all the Mails are sucessfully send as far as i can tell (i confirmed it in about 30 of 30 cases).

$this->mailer->isSMTP();
$this->mailer->Timeout = 300;
$this->mailer->Host = 'mail.myhost.com';
$this->mailer->SMTPAuth = true;
$this->mailer->Username = 'Domain\\Username';
$this->mailer->Password = '*****';
$this->mailer->SMTPSecure = 'tls';
$this->mailer->Port = 587;

Low level log example: (i added 2 custom debug outputs inside get_lines() of class.smtp.php to show that fgets() returns false and to show the stream_get_meta_data())

2017-08-23 13:46:05 Level 1; message: CLIENT -> SERVER: .

2017-08-23 13:46:35 Level 4; message: SMTP -> get_lines(): $data is ""
2017-08-23 13:46:35 Level 4; message: SMTP -> get_lines(): $str === false 
2017-08-23 13:46:35 Level 4; message: SMTP -> [timed_out => false, blocked => 1, eof => 1, stream_type => tcp_socket/ssl, mode => r+, unread_bytes => 0, seekable => false]
2017-08-23 13:46:35 Level 2; message: SERVER -> CLIENT: 
2017-08-23 13:46:35 Level 1; message: SMTP ERROR: DATA END command failed: 

In the other cases with response faster than 30s it would look like:

2017-08-23 23:25:02 Level 1; message: CLIENT -> SERVER: .
2017-08-23 23:25:28 Level 4; message: SMTP -> get_lines(): $data is ""
2017-08-23 23:25:28 Level 4; message: SMTP -> get_lines(): $str is  "250 2.6.0 <...> [InternalId=10677288697896, Hostname=myhost] 32443 bytes in 26.353, 1,202 KB/sec Queued mail for delivery"
2017-08-23 23:25:28 Level 2; message: SERVER -> CLIENT: 250 2.6.0 <...> [InternalId=10677288697896, Hostname=myhost] 32443 bytes in 26.353, 1,202 KB/sec Queued mail for delivery
2017-08-23 23:25:28 Level 1; message: CLIENT -> SERVER: QUIT 

So what could

$str = fgets($this->smtp_conn, 515);

cause to fail after exactly 30sec (30sec after its execution, not since script start) when it is not a timeout of the stream and not a php runtime timeout. (No Exception is thrown here, i removed the @ from fgets() in the original PHPMailer code to confirm this)

Script is running without max_execution_time.

My Exchange administrator has no idea what could cause this and i dont have a point to begin with as i dont even know where the stream breaks - PHP, Webserver, Exchange, somwhere between?

Any Ideas what else i could check or what could cause this?

I'd guess that it's the max_execution_time of your PHP installation, which defaults to 30 sec, and it happens to always fail here because that's the only thing in your code that takes that long.

Try increasing it in your php.ini or calling set_time_limit() beforehand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM