24.4. Email with Attachments
Sending plain email with PHP is easy. The mail function handles all the messy protocol details behind the scenes. But if you want to send attachments, you will need to dig into an RFC, specifically RFC 1341. This RFC describes MIME, Multipurpose Internet Mail Extensions. You can read it at the faqs.org site <http://www.faqs.org/rfcs/rfc1341.html>, but I'll show you a somewhat naïve implementation.
There are several example implementations to be found on the Web. Check out David Sklar's networking section <http://px.sklar.com/section.html?id=10>. Most of these put functionality into a class and attempt to incorporate every aspect of the standard. Listing 24.6 contains code that sends email with multiple attachments ...
Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.