HomePHP Page 4 - Handling Attachments in MIME Email with PHP
Seeing the Mailer class in action - PHP
In this second tutorial of the series, Iím going to teach you how to improve the initial structure of the MIME mailer class developed in the first article by giving it the ability to work directly with attachments. Sounds fairly interesting, right? Then donít waste any more time in preliminaries and begin reading this article now!
I listed the complete definition of this improved MIME ďMailerĒ class below along with a short script that demonstrates how to use it to send a trivial message that incorporates a pair of attached files.
Hereís the corresponding code sample:
// create a new instance of the 'Mailer' class
$mailer=&new Mailer('email@example.com,'firstname.lastname@example.org','Testing mailer class','Hello buddy. Is everything doing fine over there?');
// add some attachments
// send MIME email
Thatís all the source code that you need to get the ďMailerĒ class working as expected. For this particular case, I utilized the class to send a simple message in plain text along with a couple of attached GIF files. This should clearly show its considerable functionality.
As always, youíre free to use the code samples shown in this tutorial in case you want to use the previous ďMailerĒ class to improve your existing skills in sending MIME email with PHP.
Thatís all for the moment. In this second chapter of the series, I taught you how to extend the existing functionality of the previous MIME mailer class in order to provide it with the capacity to work with attachments.
In the next tutorial, Iím going to improve the business logic implemented by the class, particularly when it comes to determining the MIME type of an attached file. This will make it slightly more compact and efficient.
Now that youíve been warned about the subject of the upcoming article, you wonít want to miss it!