HomePHP Page 4 - Composing Messages in HTML for MIME Email with PHP
Sending email in HTML format using the MIME mailer class - PHP
Welcome to the fourth episode of the series, "Sending MIME email with PHP." In this article, Iím going to show you how to provide the MIME mailer class with the ability to send email messages in HTML format. This will greatly extend its functionality, so don't miss this tutorial.
Below I coded a basic script, which comes in handy for illustrating the functionality of the ďMailerĒ class, especially when it comes to sending email messages in HTML.
Hereís the corresponding code sample:
// create a new instance of the 'Mailer' class
$mailer=&new Mailer('firstname.lastname@example.org,'email@example.com','Testing mailer class','Hello buddy. I am sending to you a couple of fun images.');
$mailer->addHTML('<p>This is a simple paragraph formatted in HTML</p>');
$mailer->addHTML('<p>This is another paragraph formatted in HTML</p>');
// add some attachments
// send MIME email
As shown in the above example, I used the MIME mailer class to send a simple text message with a couple of attached files. However, Iím also sending HTML code embedded into the message in question.
As usual, I suggest you to test the previous ďMailerĒ class by incorporating your own improvements. Itís going to be an educational experience, trust me!
Thatís all for now. In this fourth installment of the series, I taught you how to build a modular MIME mailer class thatís capable of sending email in both plain text and HTML formats. In addition, the class supports working with file attachments, so I guess it should be quite helpful when it comes to learning the basics of sending MIME email with PHP.
In the last chapter, Iíll be porting the complete source code of the class to PHP 5. This will take advantage of its improved object model. Donít miss the upcoming article!