Simpliest way to test SMTP connection

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
godza
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 1:54 pm

Simpliest way to test SMTP connection

Post by godza »

Can someone help me with this problem.

I am trying to check if user has provided valid login credentials and connection parameters.

Code: Select all

 
    $smtp = new Swift_Connection_SMTP($mailing_host, $mailing_port, $mailing_encryption);
    $smtp->setUsername($mailing_username);
    $smtp->setPassword($mailing_password);
 
    $swift = new Swift($smtp);
    $result = $swift->connect();
 
After executing this piece of code, nothing happens. $result is NULL. How do i find error code and error message.
I need solution that works with both PHP5 and PHP4.

Thank you in advance!
jamchild
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 8:18 pm

Re: Simpliest way to test SMTP connection

Post by jamchild »

Try wrapping your $swift->connect like this,

Code: Select all

 
try {
  // [...] your other connection code here
  $swift = new Swift($smtp);
} catch (Swift_ConnectionException $e) {
  // show error
  print_r($e->getMessage());
}
 
godza
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 1:54 pm

Re: Simpliest way to test SMTP connection

Post by godza »

Thank you, this is working, but, it's php5 solution only. What to do if i have php4?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Simpliest way to test SMTP connection

Post by Chris Corbyn »

godza wrote:Thank you, this is working, but, it's php5 solution only. What to do if i have php4?
Upgrade to PHP5 ;)

You can use an error handler in PHP4 but it's hacky at best. Look up error handling on php.net and go from there.

Again, if you could move to PHP5 (scream down the phone at your host if they won't do it :P) you'd be able to do so much more with PHP. Zend no longer support PHP4 and neither do I ;)
godza
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 1:54 pm

Re: Simpliest way to test SMTP connection

Post by godza »

Yup, i know that is time to move on to php5, but we are writing application that is backward php4 compatible, so i think i will try to use set_error_handler.

Thank you guys for prompt response.
Post Reply