phpmailerHow can I set a timeout for PHPMailer SMTP?
The easiest way to set a timeout for PHPMailer SMTP is to use the setTimeout()
method. This method takes an integer value as an argument, which is the time in seconds.
Example code
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set timeout
$mail->setTimeout(30);
The setTimeout()
method can also be used to set separate timeouts for the SMTP connection and the SMTP data transfer. To do this, two integer values are passed as arguments, the first being the connection timeout and the second being the data transfer timeout.
Example code
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set timeout
$mail->setTimeout(20, 10);
This sets the SMTP connection timeout to 20 seconds and the SMTP data transfer timeout to 10 seconds.
It is also possible to set the timeout for the SMTP connection using the SMTPOptions
property. This property takes an array of options as an argument. The timeout
key in the array sets the timeout for the SMTP connection.
Example code
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set timeout
$mail->SMTPOptions = array(
'timeout' => 30
);
This sets the SMTP connection timeout to 30 seconds.
For more information, see the PHPMailer documentation.
More of Phpmailer
- How do I configure PHPmailer to use Zoho SMTP?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer with Yii2?
- How do I set the X-Mailer header using PHPMailer?
- How can I use PHPMailer without SMTP secure?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I determine which version of PHPMailer I'm using?
- How can I send a UTF-8 encoded email using PHPMailer?
See more codes...