Zend Certified Engineer

phpguru.org

Free PHP, Javascript and C# code

SMTP class rehash


6th December 2007, 1228 views

With the help of a few anonymous people (thanks), I've rehashed the smtp class for PHP5 and made it available. It should be considered beater quality at the moment, so don't go using it for production code unless you like to live dangerously (Ooooh...). Here is some sample code to send an email:

try {
    $smtp = new SMTP($smtp_server, $smtp_port, $smtp_helo, $smtp_auth, $smtp_user, $smtp_pass);
    $smtp->Connect();
    $smtp->Send(array($smtp_recipient), $smtp_from, array('Subject' => 'The subject', 'To' => $smtp_recipient, 'From'    => $smtp_from), $message);

} catch (SMTPException $e) {
    echo $e->GetMessage();
}

Top 10 referrering pages

  1. http://www.google.com/search?hl=en&q=php+SMTP+set... (2 referrals)
  2. http://www.google.com/search?q=ini_set+smtp&ie=ut... (2 referrals)
  3. http://www.megite.com/url/:www_lifehacker_com/sof... (1 referrals)
  4. http://209.85.135.104/translate_c?hl=de&sl=en&u=h... (1 referrals)
  5. http://www.richardheyes.com/downloads/pcntl/?M=A (1 referrals)
  6. http://www.google.com/search?q=+PEAR+gmail+smtp&h... (1 referrals)
  7. http://209.85.171.104/translate_c?hl=es&sl=en&tl=... (1 referrals)
  8. http://www.yandex.ru/yandsearch?text=smtp+php5&rp... (1 referrals)
  9. http://www.google.com/search?q=htmlmimemail5+smtp... (1 referrals)
  10. http://www.google.ca/search?q=smtp+via+gmail+php&... (1 referrals)
- +
Rate this article

Link to me

If you use any of the code on this site (and if you don't I guess) or it makes your life easier, I'd appreciate a link - http://www.phpguru.org. Thanks!

RSS Feed for Comments

Comments

Author: Gareth Heyes
Posted: 6th December 2007 15:22
Cool good work, I'll check it out
Quote
Author: Richard Quadling
Posted: 6th December 2007 16:21
Is this a replacement for the smtp class in htmlmimemail5 ?

Quote
Author: Richard Heyes
Posted: 6th December 2007 16:25
Essentially yes, but there's no need to upgrade for the sake of it. It's an update which simply brings it up to my current coding standards. There isn'y any new features.
Quote
Author: Richard Quadling
Posted: 6th December 2007 16:30
OK.

OOI, are you aware of the break in the windows mail() function in PHP5.3.0-dev?

Return true but does nothing.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

ini_set('SMTP', 'gmail-smtp-in.l.google.com'); // Force GMail to be the server.

$s_Email = 'RQuadling' . '@' . 'GMail.com';
ini_set('sendmail_from', $s_Email); // Message is from me.

var_dump(mail($s_Email, PHP_VERSION, 'Your message', "from:$s_Email"));
?>

Running this as ...

C:\php[456]\php -n C:\testmail.php

Works on ...

PHP 4.4.7-dev (cgi-fcgi) (built: Mar 25 2007 21:02:43)
PHP 5.2.2RC2-dev (cli) (built: Apr 18 2007 08:03:01)
PHP 6.0.0-dev (cli) (built: Sep 13 2007 02:04:41)

Doesn't work on ...

PHP 5.3.0-dev (cli) (built: Nov 20 2007 08:19:12)


Quote
Author: Richard Quadling
Posted: 6th December 2007 16:30
OK.

OOI, are you aware of the break in the windows mail() function in PHP5.3.0-dev?

Return true but does nothing.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

ini_set('SMTP', 'gmail-smtp-in.l.google.com'); // Force GMail to be the server.

$s_Email = 'RQuadling' . '@' . 'GMail.com';
ini_set('sendmail_from', $s_Email); // Message is from me.

var_dump(mail($s_Email, PHP_VERSION, 'Your message', "from:$s_Email"));
?>

Running this as ...

C:\php[456]\php -n C:\testmail.php

Works on ...

PHP 4.4.7-dev (cgi-fcgi) (built: Mar 25 2007 21:02:43)
PHP 5.2.2RC2-dev (cli) (built: Apr 18 2007 08:03:01)
PHP 6.0.0-dev (cli) (built: Sep 13 2007 02:04:41)

Doesn't work on ...

PHP 5.3.0-dev (cli) (built: Nov 20 2007 08:19:12)


Quote
Author: Richard Heyes
Posted: 6th December 2007 16:36
Ummm... so? As long as it works when 5.3.x is released to the public...
Quote
Author: Rafael
Posted: 11th December 2007 18:31
Hi, I need to use this with attachment how can I do that??? there is no method for that case on your class
Quote
Author: Richard Heyes
Posted: 11th December 2007 18:59
Rafael:
> Hi, I need to use this with attachment how can I
> do that??? there is no method for that case on
> your class

You should look at the mime class,
Quote

Post Comment

Your name:
Your email:
(Don't worry, I won't spam you. Also, if you do put your email address in here, you'll get notified of new comments. If you don't, you won't.)
Comments:
  Do not post support type questions please

 
CAPTCHA image If you can't read the CAPTCHA then press the submit button to get another. Your comment will re-appear (as if by magic...).
Captcha image