Home > Features > Sending HTML E-mail Using PHP • Bookmark   • Newsletters   • Register Search Options


Sending HTML E-mail Using PHP

Sending HTML E-mail Using PHP

July 15, 2003
Text size: 
Get XBIZ News
XBIZ Research
Will virtual reality boost the paysite market?
Yes, it will soon
Yes, but in a few years
Out of 151 votes. Results based on votes submitted by members of XBIZ.net social network.

Not too long ago there was a discussion about the pros and cons of having a message board on a pay site as a means of increasing customer interactivity, feedback, and retention. In this enlightening discussion was overlooked another, perhaps simpler and yet more practical and effective tool - the newsletter.

An informative, helpful, entertaining, and attractive newsletter (especially an HTML-formatted one) can be a tremendous asset to any e-commerce enterprise. Successfully producing and delivering one is a process not without its share of concerns and considerations, however.

Beyond the dynamics of producing compelling content for a newsletter, there are a handful of technical requirements that are occasionally problematic to overcome, depending upon your hardware and software infrastructure and configuration. One way to make the process run smoother is to send HTML-formatted mailings through a PHP gateway script that comes pre-configured with the necessary headers and other required information.

Valentin Ciocea from Ciocea Soft was kind enough to send us a PHP script that pre-configures your e-mail headers, then pulls an HTML file (in this case "newsletter.html") from your hard drive, and then sends it to the designated list of recipients.

Just don’t forget to use absolute references (such as <IMG src=http://www.site.com/image.jpg>) to included objects when building your HTML page.


// read the HTML newsletter from hard drive :
$html=fread($fis,filesize ($path."newsletter.html"));

$subject="Here is your newsletter.";

//add From: header
$headers = "From: $sender\r\n";

//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";

//unique boundary
$boundary = uniqid("HTMLDEMO");

//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";

//message to people with clients who don't
//understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";

//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("This e-mail contains the newsletter, but you are unable to see because it is in HTML and your email client can't display it."));

//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($html));

//send message
mail($receiver, $subject, "", $headers);


Of course, YOU need to build the HTML page that you want to use for your mailing, and have a proper opt-in mail list as well, but we’ll give you this fully-comented e-mailing script to help get you started. If you have trouble with this script, contact your server admin, or Valentin, or ask about it on XBiz' Coder's Underground message board. Good Luck! ~ Stephen


International Distributors Discuss Global Sex Toy Market Trends

The adult entertainment industry can bring considerable rewards to businesses that think globally, and that includes the lucrative sex toys/pleasure products market. European, Australian or Japanese companies... More »

Pleasure Product Manufacturers Talk Global Strategies for Success

From branding to shipping, companies with international reach talk to XBIZ about how to appeal to consumers worldwide. At LELO, trade marketing manager Zabrina Law says there is not a lot of variation... More »

E.U. Sex Toy Brands Bolster U.S. Market With Innovation

Europeans are living the American dream. Five weeks of paid vacation, government-funded medicine and education, and a healthier approach to sexual wellness are commonplace for our cousins across the ocean.... More »
Stay informed of the latest industry developments. Get XBIZ newsletters delivered to your inbox. Subscribe today!
Enter email address:

* To manage existing subscriptions click here.

Submit your press release to
multiple news outlets with 1 click.
Subscribe to RSS news feeds or
add free content to your website.
Access XBIZ news and articles
with your mobile device.
Access the latest issues of the industry's leading trade publications in digital form. View online or download for offline viewing.



Nov 04 - Nov 06
Edison, New Jersey

2016 Inked Awards

Nov 05 - Nov 05
Edison, New Jersey

XBIZ 2017

Jan 09 - Jan 13
Hollywood, CA

XBIZ Awards 2017

Jan 12 - Jan 12
Los Angeles, CA
Everyday thousands of business professionals browse XBIZ's industry directory for quality products and services. Not listed yet? Your company could be losing potential new business. Submit your company today!
Use XBIZ RSS feeds to stay informed of the latest industry developments or as a content syndication tool for your website!