I'm using gmail as my smtp server with phpmailer().
$mail->Host= "ssl://smtp.gmail.com"
How do i specify a separate smtp server just as a back up incase the connection to gmail fails ?
I'm using gmail as my smtp server with phpmailer().
$mail->Host= "ssl://smtp.gmail.com"
How do i specify a separate smtp server just as a back up incase the connection to gmail fails ?
No need for all that hard work, it's built in to PHPMailer. When you set the host, just add more than one in a semicolon-delimited list (you can also specify security settings at the same time), like this:
PHPMailer will try them all, in the provided order, before giving up. Make sure you are using a fairly recent version of PHPMailer as there were bugs in this area in older versions.
Check out this tutorial: http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
And go to the section:
Advanced setup with fall-back SMTP server
First add the variables for the backup email service, something like:
Then we modify the mail send function to incorporate our backup plan.
And finally use our new function, using our backup (by passing
$is_gmail = false
) only if necessary.Example code was taken from the tutorial linked above.