HomePHP Page 4 - A Better Way to Determine MIME Types for MIME Email with PHP
Putting the modified “Mailer” class to work - PHP
Welcome to the third episode of the series entitled “Sending MIME email with PHP.” This series progressively teaches you how to construct a reusable MIME mailer class that can be easily integrated into your existing PHP applications. In this article, I’ll be modifying the implementation of the “getMimeTypes()” method, included with this mailer class, in order to make it more compact and efficient.
Below I coded a final hands-on example that demonstrates how to use the “Mailer” class, after its original signature has been modified.
Here is the corresponding code sample:
// create a new instance of the 'Mailer' class
$mailer=&new Mailer('alejandro@mydomain.com,'mybuddy@yourdomain.com','Testing mailer class','Hello buddy. I am sending you a couple of fun images.');
// add some attachments
$mailer->addAttachment('file1.jpg');
$mailer->addAttachment('file.jpg');
// send MIME email
$mailer->send();
As you can see, changing the way the “Mailer” class does some of its things doesn’t imply that its API must change too. The above example demonstrates this concept very clearly, since the steps taken to use the class in question are the same steps you learned in the two previous tutorials of the series.
And lastly, here’s my final suggestion: feel free to introduce your own modifications to the pertaining “Mailer” class, not only to extend its functionality, but to improve your background in sending MIME email with PHP.
Final thoughts
In this third episode of the series, I showed you how to improve the business logic of the previous MIME mailer class, specifically when it comes to determining the MIME type of the attached files. As you saw before, this process was performed by creating an additional array of class properties. So you shouldn’t have major problems understanding how it functions.
In the next article, I’m going to continue extending the functionality of this MIME mailer class by providing it with the capacity to send email messages in HTML format.
The article will be insightful, trust me. I hope you don’t miss the upcoming tutorial!