error catching issue

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
frankie
Forum Newbie
Posts: 2
Joined: Tue Apr 14, 2009 8:50 pm

error catching issue

Post by frankie »

I'm trying to have swift mailer be as fail proof as possible (you've sure made it very easy! - great work) but I am not beeing able to cope when sendmail is down. Given the following example:

Code: Select all

// use all transports for failover safety
$transport_smtp = Swift_SmtpTransport::newInstance("localhost");
$transport_sendmail = Swift_SendmailTransport::newInstance();
$transport_native = Swift_MailTransport::newInstance();
        
try {
    $this->swift = new Swift_Mailer(Swift_FailoverTransport::newInstance(array(
        $transport_smtp,
        $transport_sendmail,
        $transport_native
    )));
} catch (Swift_TransportException $e) {
    echo "Could not initialize any transporter (smtp, sendmail and nativemail failure!)";
    return false;
}
If I turn sendmail off (/etc/rc.d/init.d/sendmail stop) the catch part is not triggered and the function keeps running. I do get a php error:

A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to localhost:25 (Connection refused)
Filename: Transport/StreamBuffer.php
Line Number: 243

Am I doing it all wrong?

Thank you,
Frankie
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: error catching issue

Post by Chris Corbyn »

The exception is thrown from send() in version 4.
frankie
Forum Newbie
Posts: 2
Joined: Tue Apr 14, 2009 8:50 pm

Re: error catching issue

Post by frankie »

Thanks Chris!

I owe a lunch. I'm planning to visit Australia in the next couple of years - vacation - so, if your up to it, I'll contact you then.

Thanks once again and congrats on the great software library you developed!

Francisco
Post Reply