Preventing "Uncaught Exception"

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
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Preventing "Uncaught Exception"

Post by VinceP »

Hi,

It's been a late night, and for the life of me I can't figure out how to resolve the error analysis for Swift.

I include Swift and attempt to send an e-mail using code such as:

Code: Select all

if (class->swiftmail($fields)) { // Do something }
This obviously seems to work when successful, but when I deliberately fudge the authentication, Swift throws out the following:

Code: Select all

Fatal error:
Uncaught Error of type [swift_connectionexception] with message [Authentication failed using username 'blah@domain.com' and password '********']
Can I suppress these errors and just have Swift throw a return status of 0 instead? I'm using PHP4 if it makes any difference. Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Preventing "Uncaught Exception"

Post by Chris Corbyn »

It's the one bit I hate the most about the PHP4 version and the reason why in 11 days time I'm dropping support for it ;)

The library is developed under PHP5 and uses exceptions quite heavily. Exceptions don't exist in PHP4 and there's no "equivalent" in terms of program flow. Since I didn't want to maintain two completely different sources (i.e. in terms of logic) I came up with this -- flaky at best -- solution:

http://www.swiftmailer.org/wikidocs/v3/misc/php4errors

I'd suggest upgrading to PHP5 asap considering I'm not supporting it any longer, nor are PHP/Zend themselves. Cutoff date is Feb 8th for Swift. The old version will remain available but bugfixes and new versions will be for >= PHP 5.2 only.
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Re: Preventing "Uncaught Exception"

Post by VinceP »

Version preference aside, it's not an option to upgrade to PHP5 on this server unfortunately, so I'm stuck with it :(

I read that documentation page before I posted, and to be honest it had me a little confused. Maybe I'm just tired :)

What's "theMethod()" all about?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Preventing "Uncaught Exception"

Post by Chris Corbyn »

theMethod() is just pseudo code.

For your connection failure, try this:

Code: Select all

Swift_Errors::expect($e, "Swift_Exception");
$swift = new Swift( ... );
if (!is_null($e)) {
  //error occured
} else {
  Swift_Error::clear("Swift_Exception");
}
Your host should feel pressured to upgrade if enough people ask ;) PHP 4 officially died in December 2007 so your host will no longer get support for it, nor security updates.
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Re: Preventing "Uncaught Exception"

Post by VinceP »

Yep, I know PHP4 has died, but it's a control panel solution so not upgradeable until they change their source packages. Speaking as someone who has worked in the hosting industry for over 7 years, I know forcing your customers to upgrade can cause more problems than not upgrading to begin with. You'd be shocked at how many of them use 4+ year old scripts that contain deprecated functions that don't work on upgraded systems. Always a good idea to keep an old server or 2 around for cases like that, simply because they don't want to get their code rewritten ;)

Anyway, back to the subject at hand....

Here's what I currently have:

Code: Select all

 
Swift_Errors::expect($e, "Swift_Exception");
$smtp =& new Swift($conn);
$subject = "Subject"
$body = "Random body";
$message =& new Swift_Message($subject, $body);
$result = $smtp->send($message, new Swift_Address($to, $to), new Swift_Address($from, "Company Name"));
 
With your new line added, I now get a different error:

Code: Select all

 
Fatal error:
Uncaught Error of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response [530 5.5.1 Authentication Required m34sm1737189waf.48]]
 
I assume it doesn't matter that I'm not checking for errors immediately after creating the Swift instance? I obviously need to set the message content, so figured I could check after attempting to send?

Still haven't slept, so sorry if I'm completely off the ball here :)
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Re: Preventing "Uncaught Exception"

Post by VinceP »

Any ideas, Chris?
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Re: Preventing "Uncaught Exception"

Post by VinceP »

Just FYI, I decided to scrap SwiftMailer completely. Your lack of response to this thread towards the end, despite your recent activity in other threads, was the primary factor. I will, also, not be using SwiftMailer in any future projects.

If you, personally, don't want to support the PHP4 version of SwiftMailer because you feel that PHP4 is "dead", then I can only suggest you remove it from your website and/or put a disclaimer saying that you refuse to support it, and people should use PHP5 version instead. Ignoring the thread, though, completely destroys your credibility. Understandably I can't have my projects use something which the author appears to not want to support in certain instances.

Regardless of your personal views on the "expiration" of PHP4, people will continue to use it (and perhaps the PHP4 version of SwiftMailer) for many years to come. If you don't want to support it *now*, then do something about it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Preventing "Uncaught Exception"

Post by Chris Corbyn »

I'm sorry that my volunteer efforts leave a bad taste in your mouth. The lack of respect shown by people who rant at me like you have just done does not give me a great feeling about continuing which this project -- though I will because the majority of people appreciate the (quite literally) thousands of hours development that has gone into this.

Just for the record, I wasn't ignoring you, I read every thread that gets posted here it's just that I don't always have an immediate answer to everything.

In future I suggest you show some respect to the developers of the open source software you freely download and freely request support for.

Good day :banghead:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Preventing "Uncaught Exception"

Post by Christopher »

VinceP wrote:Just FYI, I decided to scrap SwiftMailer completely. Your lack of response to this thread towards the end, despite your recent activity in other threads, was the primary factor. I will, also, not be using SwiftMailer in any future projects.
I read the thread and it looks like you got answers within hours of each posting.
VinceP wrote:If you, personally, don't want to support the PHP4 version of SwiftMailer because you feel that PHP4 is "dead", then I can only suggest you remove it from your website and/or put a disclaimer saying that you refuse to support it, and people should use PHP5 version instead. Ignoring the thread, though, completely destroys your credibility. Understandably I can't have my projects use something which the author appears to not want to support in certain instances.
So you are complaining that someone will not provide free help for you to do your job? Just because you are not able to get the PHP4 version to work does not mean that many other may not find it useful. In fact by your own argument, Chris should not remove the PHP4 version for just the same reasons you choose to "keep old servers" around. Your apparently poor choice of control panel software does not reflect on SwiftMailer or Chris.
VinceP wrote:Regardless of your personal views on the "expiration" of PHP4, people will continue to use it (and perhaps the PHP4 version of SwiftMailer) for many years to come. If you don't want to support it *now*, then do something about it.
Those views are not "personal" views. PHP4 is no longer supported. The PHP4 versions of many PHP applications are also no longer supported. Your opinion that free PHP4 software should be supported for you is the only "personal view" I see here.

You have been inexcusably rude to someone who is kind enough to provide free software and support. I think you should apologize.
(#10850)
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Re: Preventing "Uncaught Exception"

Post by Selkirk »

How much does a swift mailer support contract cost again? :roll:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Preventing "Uncaught Exception"

Post by John Cartwright »

arborint wrote:You have been inexcusably rude to someone who is kind enough to provide free software and support. I think you should apologize.
Agreed. That was selfless of you. However, it's your loss if you want to drop support for the best php email library available.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Preventing "Uncaught Exception"

Post by Benjamin »

Keep up the good work Chris. I think people forget that there's a person on the other side of the keyboard sometimes.
Post Reply