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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: