In accordance with the concepts expressed in the previous section, I’ve set up a practical example aimed at demonstrating the functionality offered by the MIME mailer class now that it has been migrated to PHP 5. The pertaining code sample looks like this: try{ // create a new instance of the 'Mailer' class $mailer=new Mailer // add some HTML to the message $mailer->addHTML('<strong>This text is formatted with HTML</strong>'); // add some attachments $mailer->addAttachment('file1.gif'); $mailer->addAttachment('file2.gif'); // send MIME email $mailer->send(); } catch(Exception $e){ echo $e->getMessage(); exit(); } As you can see, the API of the “Mailer” class allows us to send email messages in both plain text and HTML formats. And if all of these features aren’t good enough for you, it also handles file attachments in a simple way. Finally, I recommend you tweak the source code of this class and incorporate your own modifications in order to suit your personal requirements. Final thoughts It’s hard to believe, but we’ve come to the end of this journey. I hope the whole experience has been instructive, since I simply tried to provide you with some useful pointers to help you start using MIME email within your own PHP applications. In a case like this, I used an object-oriented approach to send email, but you can utilize a procedural methodology and obtain practically the same results. See you in the next PHP development tutorial!
blog comments powered by Disqus |
|
|
|
|
|
|
|