It started with a simple requirement: A project I’m working on needed to send email with attachments. Now, I could’ve just rigged something up to get the job done, but I’d just drank a NOS and I was feeling adventurous.
What I would up with is an EmailHandler class with a couple added features that will make handling email in project moving forward a whole lot easier and cleaner than with a few variables and php’s mail() function. This little beast covers a few important things:
- Multiple Attachments
- Dual-Type mail: HTML support with fallback to plain-text if the recipient’s email client doesn’t support HTML mail
- Submission either directy to php mail() or to a mailer queue db table for bulk mailing.
- A clean, structured interface.
Alright, here’s the goods:
Note: You can see in the queue() method I’m using a non-standard db interface. You’ll probably want to tweak that func to work with your code.
So pretty straightforward, right? Here’s a quick example covering most of the features:
And that’s all there is to it.
So, where to begin. I decided to start up a new blog since that’s the thing we apparently do these days. From time to time I’ve got news on current projects, or neat little snippets of code I’d like to share with my colleagues, and I figure there’s a chance other people could make decent use of some of this info as well.
It also goes without saying that I’m a pretty huge dork, so in addition to coding-related stuff, I’ll likely also post entertaining stuff of the nerdy variety. Whoopie.