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 can I configure PHPMailer to work with GoDaddy?
- How can I use PHPMailer without SMTP secure?
- How do I use PHPMailer to attach a ZIP file?
- How can I install the missing openssl extension for the PHPMailer library?
- How do I use PHPMailer with OAuth2 authentication for Microsoft accounts?
- How can I use PHPMailer to send emails with a Yahoo account?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I configure PHPMailer to use a proxy?
- How can I use PHPMailer with Laravel?
- How do I manually install PHPMailer?
See more codes...