Home/
 www.icosaedro.it 

 PHPMailer-ico

PHPMailer is one of the most popular PHP classes used to build and send complex MIME formatted emails. Unfortunately, the original class available at Sourceforge is for PHP 4 only. Here is my version of the same class converted to PHP 5, with some enhancement and cleaned-up source.

Index

Features
How I'd converted the class
Documentation
Credits
Changes
Download

Features

PHPMailer-ico allows to send email in various formats: as plain text, as HTML with possibly embedded images and sounds, and with files attached. PHPMailer-ico apply the MIME specifications either to the header and to the body of the email, allowing to send subjects and texts encoded in any charset. There are three possible sending methods: through the built-in mail() function, through a sendmail program (as provided by Sendmail and Qmail), and directly via SMTP protocol to a mail server.

How I'd converted the class

The properties were marked as var in PHP 4, whereas PHP 5 requires the public or the private qualifier. Private and static properties now have their correct attribute. These are the simpler changes needed to run the PHPMailer classes under PHP 5.

PHP 4 does not has the class constants, so that some values were improperly defined as properties. Now they are proper const values.

The source was also rearranged in order to apply the PHPLint validator (www.icosaedro.it/phplint). To this aim, methods had to be resorted in bottom-up order, since PHPLint is a single-pass parser and it requires to see the definition of things before they can be used.

When I started this work, PHPLint did not supported yet the PhpDoc comments, so the the DocBlock comments are now converted to the PHPLint Documentator format /*. DOC ... .*/, but with some enhanced explanations and corrections.

Parameters and returned values that were generic "mixed" have now their proper type, so enforcing the strictness of the validation and improving the documentation automatically generated by PHPLint.

The original source used arrays to hold a generic set of heterogeneous data, but the code was difficult to read and to maintain. For example, how to remember that $attachment[0] is the pathfile and $attachment[7] is the content ID? Introducing a new private class PHPMailer_Attachment in place of these arrays made the intent of the programmer more evident: $attachment->path and $attachment->cid are self-explanatory and lets the validator to do its job better.

The source is now 20% shorter than the original one.

Support for the exceptions has been added, and some exceptional error conditions can now be handled via try...catch.

Documentation

The original, still to be updated, documentation is provided along the PHPMailer-ico package. The documentation generated by PHPLint Documentator is also included, and it is the definitive reference for the new features; there documents are also available in this WEB page:

Credits

PHPMailrer-ico is based on PHPMailer 1.73 and it is released under the LGPL 2.1 license; see the file LICENSE for more details.

PHPMailer 1.73 is released under the same license and it was originally written by Brent R. Matzelle. Currently it is maintained by several programmers. Its official WEB site is http://sourceforge.net/projects/phpmailer.

Changes

2007-06-13 Added method PHPMailer::IsValidEmailAddress(). Methods AddAddress(), AddCC(), AddBcc() and AddReplyTo() now thow exception on invalid email addresses to prevent SMTP commands injection.

2007-04-15 First public release of PHPMailer-ico.

Download

Stable version: PHPMailer-ico-20070613.tar.gz
Source of the PHPMailer-ico class and SMTP class for PHP 5, based on the 1.73 version of PHPMailer. Includes some examples. Original (still to be updated) documentation is included. The documentation automatically generated by PHPLint Documentator is included in HTML format.

Latest version under development: see CVS server.


Umberto Salsi

Contact
Site map
Home/