Mail Call!

      5 Comments on Mail Call!

p. Everybody needs to send mail from their application at one point or another. It’s like using a database or a sledge-hammer, sooner or later, you are going to want to do it. But what’s the best tool? Yesterday I got an email from a “friend of mine”:http://www.sqlyog.com asking me this question. Since I respect him and his team and they didn’t know the answer, I figure there might be others out there who struggle with this. (It will come as no surprise to those of you who read this site regularly that this is not a comprehensive list but more of a primer to get you going. Comprehensive lists are just too hard.)

p. First and foremost is the venerable “mail()”:http://us2.php.net/manual/en/function.mail.php function built into PHP. If your needs are modest, this will work just fine. It is simple to use, allows you to fire off an email to multiple users at once and allows you *some* control over what is happening. You do trade off functionality for ease of use but in a lot of cases, this is enough. “There are some gotchas”:http://www.securephpwiki.com/index.php/Email_Injection to be aware of so like any technology, make sure you understand it before you deploy.

p. Next, “Pear_Mail”:http://pear.php.net/package/Mail. One thing you can say about Pear_Mail is it’s stable. The last release was 09/13/2005. Pear_Mail’s documentation skews towards the PHPDoc style “Here’s what you get” documentation. To it’s credit there are also some “examples”:http://pear.php.net/manual/en/package.mail.mail.send.php of how to use it. RFC822 Address validation and an object oriented interface are the two main things that Pear_mail give you. Pear_Mail is like a compact car, it gets the job done with little or no frills. In cases where you need a little more than mail() gives you, Pear_Mail may be all you need.

p. As a new kid on the block, the “Zend Framework”:http://framework.zend.com introduces “Zend_Mail”:http://framework.zend.com/manual/en/zend.mail.html with the following features:

* Multiple recipients
* Send email through multiple SMTP accounts
* Send multiple emails in one connection
* HTML email
* Multipart emails for providing text alternative to HTML
* MIME attachments
* Custom mail headers
* Control over character sets
* Support for 8bit, base64, binary, and quoted-printable encoding
* Support for alternative transports

At its current “preview” state, Zend_Mail is really only “missing SMTP authentication”:http://framework.zend.com/manual/en/zend.mail.smtp-authentication.html and embedded image support. I expect more features to come as it progresses.

p. But Cal, I hear you out there saying, I need rich content emails, I need to send directly to SMTP servers, I really need something that will let me message my closest 25,000 friends to tell them how they too can get a free iPod. You are evil, but I’ll help you anyhow. Next in line is one of my favorite tools and the one that I recommended to my friend that he deploy on his site. “PHPMailer”:http://phpmailer.sourceforge.net/ is available at everybody’s best buddy, SourceForge and is a complete mailing solution. [Warning: blatent content ripoff ahead] Here’s their overview feature list.

* Can send emails with multiple TOs, CCs, BCCs and REPLY-TOs
* Redundant SMTP servers
* HTML email with multipart/alternative emails for mail clients that do not read HTML email
* Support for 8bit, base64, binary, and quoted-printable encoding
* Uses the same methods as the very popular AspEmail active server (COM) component
* SMTP authentication
* Word wrap
* Address reset functions
* Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Imail, Exchange, etc
* Works on any platform
* Flexible debugging
* Custom mail headers
* Multiple fs, string, and binary attachments (those from database, string, etc)
* Embedded image support

p. It’s truly a marvel of modern programming. The “documentation”:http://phpmailer.sourceforge.net/docs/ is again PHPDoc style so be prepared to go on on an Easter Egg hunt if you need specific information but thankfully both the download and the web site include easy to follow “examples”:http://phpmailer.sourceforge.net/extending.html.

p. Well that’s it for today. Please feel free to send me those ever popular “You forgot my favorite mailer class” emails. I especially like the ones that go longer than 2 pages explaining why your favorite is the best. Really, those make my day.

=C=