Send HTML and Plain Text Versions of Email

Recently, I've been dealing with sending email from applications an awful lot. At first glance, sending a basic message from PHP is easy:

<?php mail('test@example.com', 'Subject Line', 'A message!'); ?> Sending complex messages with HTML formatting and/or attachments, however, can be tricky. Today, we're going to cover sending HTML email to a user while still including a plain text version for email clients that don't support HTML.

See the Demo | Download the Source

Part One: Understanding Email Structure

Basic email structure is something like this:

To: someone@example.com Subject: Test Email From: Test <testing@example.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx" X-Nonspam: None --==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This Is a Plain Text Email This message has no HTML. http://w3schools.com --==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <body> <h1>This Is an HTML Email</h1> <p> This message is composed in <a href="http://w3schools.com">HTML</a>. </p> </body> </html> --==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx-- This looks a little daunting at first, but if we take... read more

ITT #16: Create a Template Parsing System with PHP

One of my most recent obsessions has been with simplifying my custom CMS to allow me to generate full sites without changing anything but HTML template files and a basic configuration file. In this week's Instant Tip Tuesday, we'll explore one of the ways we can dynamically generate output and wrap it in a template file.

NOTE: This is a proof-of-concept type of thing, not a production-ready script. Be aware that I haven't used a script like this on a real site, and therefore have no idea if it's fast, effective, or even useful. For now, this is just a "hey, cool!" sort of thing; use with discretion.

Download the Files

So, What Are We Trying to Do?

To try and explain what our goal is... read more

  • «
  • 1
  • »