catchable transport connection failure

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
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

catchable transport connection failure

Post by AlexC »

G'morning,

In the 3 series of Swift Mailer, I recall there being a way to catch transport connection failures very easily. However, with 4(.0.3) a typo in the hostname when connecting (using SMTP transport here), for example, will result in PHP warnings, such as:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known
Is there a 'nice' way to handle these errors (such as catching an exception like before), so I don't in fact get them at all? This is for an application that will have its configuration adjusted by users (admins) and if they make a typo, having PHP warnings fill their logs/browser isn't too good.

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

Re: catchable transport connection failure

Post by Chris Corbyn »

PHP's own error handling features can deal with these.

Look into set_error_handler() ;)

I could use error suppression throughout my code, but it slows things down considerably.
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Re: catchable transport connection failure

Post by AlexC »

Indeed, though I'd rather not have to deal with them in that way - it wouldn't work too good for this. So there is no way of handling connection failures like in the old 3 series? :cry:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: catchable transport connection failure

Post by Chris Corbyn »

AlexC wrote:Indeed, though I'd rather not have to deal with them in that way - it wouldn't work too good for this. So there is no way of handling connection failures like in the old 3 series? :cry:
Placing an @ sign in front of the call to send() would suppress this error. In version 3, I assume you're referring to the PHP4 version of it? This was slightly different since the errors were ones generated by Swift Mailer... the PHP generated ones exhibited this same behaviour.

Code: Select all

if (@$mailer->send(...)) {
  //
}
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Re: catchable transport connection failure

Post by AlexC »

Hi Chris,

No this was in the PHP5 version, upon connection if it failed it would throw a 'Swift_ConnectionException' exception, of which I could catch and handle how I wished. I'm aware of PHPs error suppression, though it seems like a step-backwards from the 3 series in handling it. Could this be rectified in later versions, to provide a cleaner way of handling connection errors?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: catchable transport connection failure

Post by Chris Corbyn »

I;m not sure what you mean. Swift Mailer v4 still throws Exceptions on connection failures. It throws Swift_TransportException. If it's not throwing that, fsockopen() must be generating an error but returning a resource incorrectly, which is a bug in PHP itself. I've only ever seen this happen to one other person.

Are you saying that a Swift_TransportException is not thrown?
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Re: catchable transport connection failure

Post by AlexC »

From what I could see, yeah it was not throwing the exception. I don't have access to the code fully at the moment, so I shall have to check when I get home. That does sound like what is happening, though. This is on PHP 5.2.9.

Btw, unrelated to this - looking at your avatar, do you have your PPL, or is someone else flying?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: catchable transport connection failure

Post by Chris Corbyn »

AlexC wrote:Btw, unrelated to this - looking at your avatar, do you have your PPL, or is someone else flying?
My friend was flying :) PPL would be nice but I don't have one. It was a nice flight over the coast out here... over the twelve apostles.
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Re: catchable transport connection failure

Post by AlexC »

Ah, appears the exception is being thrown - not sure what was going on this morning with it then. Ghosts I tell you.

That's cool, looks like a nice place to go flying indeed! I recently got my PPL, though no where as nice to fly like that in sunny UK :D
Post Reply