Send MIME/HTML Emails with PHP Mailer
Add to Favourites
|
Sending bog-standard textual email with PHP is easy, however if you want to send some graphic-rich emails, it can get a bit tricky. But never fear, I’ve put together a simple guide of how to do just this, and you’ll be up and running sending beautifully scultped emails within minutes.
Firstly you need to download PHP Mailer ZIP file, which is a free open-source script available from Sourceforge. Once you’ve done this extract the files. Then create a directory on your web-site, for example www.yourdomain.com/phpmailer/. In this directory you need to upload the following files from the zip file…
class.phpmailer.php
class.smtp.php
phpmailer.lang-en.php (If you are English!)
Pretty much there now!
On the page that will be sending the email, either a “thank you” page or a receipt page, you need to place the follow PHP code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 //Error Reporting Featured here error_reporting(E_STRICT); //Set the Time Zone</em>, search PHP Timezone on Google for more info date_default_timezone_set("Europe/London"); //Locate the Mailer file within the directory you just set up include_once('/phpmailer/class.phpmailer.php'); $mail = new PHPMailer(); //Build the email.... $body = "<html> <body> <table width='600' border='0' cellspacing='5' cellpadding='5'> <tr> <td>This is my email!</td> </tr> </table> </body> </html>"; //Replace any dodgy characters $body = eregi_replace("[\]",'',$body); //Send the email! $mail->IsSendmail(); $mail->From = "info@yourdomain.com"; $mail->FromName = "Your Domain"; $mail->Subject = "YourDomain.com - Test Email"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer"; $mail->MsgHTML($body); $mail->AddAddress("message@recipient.com", "James Dean"); if(!$mail->Send()) { echo "Message not sent" . $mail->ErrorInfo; } else { echo "Message Sent!"; }
Nothing to it!
about the author
This article was written by Sam Davis on July 4, 2008.
Computing over a glass of Grenache Shiraz... again! Sam is the Editor of Blasted Thing. Contact Us |
related articles
comments
Leave a Reply
![]() Echo a Google Search Term on Your Page |



























