Home arrow PHP arrow Page 4 - Migrating Class Code for a MIME Email to PHP 5

Putting the brand new mailer class to work - PHP

Welcome to the final installment of the series, “Sending MIME email with PHP.” This series teaches you how to build a highly modular PHP class that can be used to send MIME-compliant email messages in plain text and HTML, while letting you work with file attachments as well. In this article, I'm going to migrate the source code from the previous article to PHP 5, taking full advantage of the new and improved features in the latest version of PHP.

TABLE OF CONTENTS:
  1. Migrating Class Code for a MIME Email to PHP 5
  2. Sending MIME email with PHP 4
  3. Porting the code of the previous MIME mailer class to PHP 5
  4. Putting the brand new mailer class to work
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
August 06, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
('alejandro@mydomain.com','somebuddy@yourdomain.com,'Testing the mailer
class','Hey, I am sending you a couple of fun images.');

// 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!



 
 
>>> 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: