Jump to content

PHPMailer capturing errors bettter


MidOhioIT

Recommended Posts

Does anyone know if there is a good way to capture errors like a SMTP timed out or a mysql timeout?  I have a newsletter system that is fairly large (50,00 plus) and there are times where the server may have a hiccup or something and it would be nice if the code would catch the timeout, sleep for a minute and retry again instead of me keep checking and noticing that it stopped over an hour later..

I am just doing the standard:

 
require_once ('class.phpmailer.php');
    // read the database and get the emails..


	   $mail = new PHPMailer();

	$mail->IsSMTP();                                   // send via SMTP
	$mail->Host     = "localhost"; // SMTP servers
	$mail->SMTPAuth = true;     // turn on SMTP authentication

Link to comment
https://forums.phpfreaks.com/topic/200332-phpmailer-capturing-errors-bettter/
Share on other sites

You could experiment with try{}catch{} blocks;

 

 
require_once ('class.phpmailer.php');
    // read the database and get the emails..

	try{
	   $mail = new PHPMailer();

	$mail->IsSMTP();                                   // send via SMTP
	$mail->Host     = "localhost"; // SMTP servers
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	}
	catch (Exception $e){
		echo($e.' - Error occured');
	}

http://php.net/manual/en/language.exceptions.php

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.