Send HTML emails using PHP with Ease
June 28th, 2008One of my clients recently asked for an email newsletter type solution where they remotely send an email address via XML to a PHP script that would then send an HTML email template off to that specific email address. I spent some time looking around at different solutions only to find that apparently no one had a solution that would meet our needs - that meant writing the script from scratch!
To send HTML emails using PHP (vs just sending a text email), what you will need to do is use PHP’s “mail” function and place the proper headers into the mail function’s “headers” field (see PHP’s mail function defenition for more info). Here is an example:
mail($email, ‘Resource Nation’,
$body,
“From: <$from>\n” .
“MIME-Version: 1.0\n” .
“Content-type: text/html; charset=iso-8859-1″);
Just replace the $email and $from variables to your liking. You can also read up in more detail on how to construct emails using PHP but my above code is a quick and easy solution for those looking to just sent emails that contain HTML. Happy HTML-emailing!




Leave a Reply