Magento WizardNo joke, this website relaunches on 1st April. New look, new features!

Contact the site  Make Money

Send MIME/HTML Emails with PHP Mailer

 Add to Favourites  
(1 rating, 1 votes)
Loading ... Loading ...

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 = "&lt;html&gt;
&lt;body&gt;
&lt;table width='600' border='0' cellspacing='5' cellpadding='5'&gt;
&lt;tr&gt;
&lt;td&gt;This is my email!&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;";
 
 
//Replace any dodgy characters
$body = eregi_replace("[\]",'',$body);
 
//Send the email!
$mail-&gt;IsSendmail();
$mail-&gt;From       = "info@yourdomain.com";
$mail-&gt;FromName   = "Your Domain";
$mail-&gt;Subject    = "YourDomain.com - Test Email";
$mail-&gt;AltBody    = "To view the message, please use an HTML compatible email viewer";
$mail-&gt;MsgHTML($body);
 
$mail-&gt;AddAddress("message@recipient.com", "James Dean");
 
if(!$mail-&gt;Send()) {
echo "Message not sent" . $mail-&gt;ErrorInfo;
} else {
echo "Message Sent!";
}

Nothing to it!

  • Digg
  • del.icio.us
  • Facebook
  • Google
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

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

 Echo a Google search term on your page
 Using PHP to pull in external data

comments

Leave a Reply




Spam protection by WP Captcha-Free


Echo a Google Search Term on Your Page


  • Sponsored Ads

  • Magento Themes
    • vtiger: great article, thank you....
  • Recent Tweets

    e eu aqui apanhando do magento.

    Magento Shop Development http://www.freelance-jobs-now.com/project-404730-magento-shop-development.html -Top #Freelance #projects

    Magento Web hosting: If you are looking for a platform to create an attractive online shop, where all the shops bu... http://bit.ly/a76ggx

    RAC - Magento Shop Development --By nfx702 on Mar 14--Max Bid: Open to fair suggestions: We are looking for a code... http://bit.ly/9czl5s

    RAC - magento template coding--By nfx702 on Mar 14--Max Bid: Open to fair suggestions: We are looking for a coder ... http://bit.ly/dC9Fwy