Before I get my hands dirty by coding this extensible MIME mailer class with PHP, I'd like to explain the functionality that I plan to implement behind its API. The class will be comprised of a few straightforward methods that will be useful for sending MIME-compliant email messages. It will also incorporate the capacity to handle simple attachments.
Once the class has been completed, you'll be able to incorporate additional methods into it, according to your personal requirements.
Having explained how this MIME mailer class will work, I'll start by defining its principal structure and implementing its constructor. Here's the first incarnation of the class in question:
// validate incoming parameters
trigger_error('Invalid value for email sender.');
trigger_error('Invalid value for email recipient.');
trigger_error('Invalid length for email subject.');
trigger_error('Invalid value for email message.');
// define some default MIME headers
// create text part of the message
// code to send text/plain messages goes here
// create message MIME headers
// code to build MIME headers goes here
// add new MIME header
// code to add MIME headers goes here
// send email
// code to send MIME email goes here
As you can see, the structure of the above "Mailer" class is quite simple to grasp and its methods are extremely intuitive. In this first step, I only implemented the corresponding constructor, but in the upcoming sections, I'll be defining the others also.
For now, pay close attention to the constructor. It accepts a few basic email-related parameters, such as the sender, the recipient, the message's subject, and finally, the text of the message itself.
The method performs a basic validation on these input arguments, and if they're considered valid, they are designated class properties. The constructor finishes its execution by defining some default MIME headers, which will be added later on when actually sending the MIME-based email message.
The rest of the methods defined by the "Mailer" class speak for themselves, since they've been named according to the task they will perform. However, they haven't been implemented concretely yet. In the upcoming section of this tutorial, I'll be doing just that. This will complete the definition of this MIME mailer class.
To see how the remaining methods of the class will be implemented, please click on the link that appears below and keep reading.
blog comments powered by Disqus