Home arrow PHP arrow 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.

TABLE OF CONTENTS:
  1. Composing Messages in HTML for MIME Email with PHP
  2. Review: sending MIME-compliant messages in plain text format
  3. Sending email messages in HTML format
  4. Sending email in HTML format using the MIME mailer class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 6
July 30, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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('alejandro@mydomain.com,'mybuddy@yourdomain.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

$mailer->addAttachment('file1.gif');

$mailer->addAttachment('file2.gif');

// send MIME email

$mailer->send();


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!

Final thoughts

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!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: