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.