Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpMailer doesn't timeout after given time

$mailer = new SMTP;    
$mailer->Timeout = 5;    
$mailer->connect($host, $port)    

This should cancel the connect() after 5 seconds, but the timeout takes much longer and don't cancel after 5 seconds.

How can I force my script to stop trying connect to the SMTP after 5 seconds?

I'm looking forward for your answers.

Best regards,

distractedGuy

like image 467
distractedGuy Avatar asked Oct 21 '25 03:10

distractedGuy


1 Answers

There are two timeouts in PHPMailer's SMTP class - Timeout and Timelimit.

Timeout applies when making the initial TCP connection. Timelimit is the duration allowed for each SMTP command's response. Both default to 5 minutes (in accordance with the RFCs) - so it could be that you are connecting quickly, but then the server is very slow to respond to commands. You should try setting the Timelimit to a lower value like this:

$mail->getSMTPInstance()->Timelimit = 5;

All of this should serve to remind you that SMTP is not intended to be an interactive, immediate protocol, so you should only be using SMTP to a nearby server that can queue your request properly.

like image 186
Synchro Avatar answered Oct 23 '25 20:10

Synchro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!