makeMIME demo

Navigation

Skip navigation.

Site search

Site navigation

Version capabilities

Version 1 could create simple emails with HTML/text alternatives and attachments. Version 2 introduced support for embedded content like images in HTML email bodies, as well as giving the correct content types for attachments and embeds. This also made it possible to attach email messages, by using an attached file type (typically using the eml file extension) that is picked up as the message/rfc822 content type.

Version 3 now complies with RFC2822's restrictions on body line length and line breaks, gives the correct content-transfer-encoding to allow it to correctly handle non-ascii content, uses quoted-printable where available (PHP versions prior to 5.3.0 will need the php_imap extension installed to enable quoted-printable transfer encoding), uses flowed format where appropriate, allows text and HTML bodies to have their charset specified to allow better support for unicode, and only gives minimal multiparts. The last of these means that, for example, multipart/mixed is only included if there are actually some attachments. This should avoid confusing naive email clients, and prevent them showing an attachment icon for the email, unless there are actually some attachments.

To download the script(s), and see the script license, use the links on the navigation panel at the top of this page.

Sample output

This script can work on its own - attachments or embeds will either need mime_content_type from the mime magic extension, or my giveMimeType library. For automatic production of a plain text body from an HTML body, my html2text library is recommended. Both of these libraries are included here for demonstration purposes. This is initialised using:

require('giveMimeType.php');
require('html2text.php');
require('makeMIME.php');

The makeMIME script automatically detects that the other scripts have been provided and uses html2text to produce the plain text body, if it has been left blank.

Tailor the demo

Body types
Attached/embedded files
Optional headers

Email output

This is a text output of the email. This script can send the email too, but I have set it in debug mode:

To: "Jessica Marple" <jes.mar@loadandproud.com>, tamina@grosvennor.com
Subject: Time to get a new bike
From: "Fran Roberts" <fran.roberts@texaco.com>
Reply-To: david.roberts@texaco.com
Cc: david@latellier.com, "Columbo" <Endeavour.Morse@texaco.com>
Bcc: sanctity@worldoflies.com
X-Priority: 4
X-Mailer: makeMIME v3.0 in PHP by MTWJ
Mime-Version: 1.0
X-Custom: I made this up
Content-Type: multipart/mixed; boundary="MTWJ_mixed_bound_0B"

This is a MIME email - please upgrade to a MIME compatible email client

--MTWJ_mixed_bound_0B
Content-Type: multipart/alternative; boundary="MTWJ_alt_bound_0B"

--MTWJ_alt_bound_0B
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

My email
          --------------------

Hi all,

[LINK: http://www.howtocreate.co.uk/] HowToCreate
[LINK: http://www.cavinguk.co.uk/] Cavinguk
[LINK: http://www.ukcaves.co.uk/] UKCaves

I have been meaning to tell you *I, yes, me* have been thinking about
buying A NEW BIKE!!!

Any ideas of what design I need?

          --------------------

David

PS, I am using Fran's email today

--MTWJ_alt_bound_0B
Content-Type: multipart/related; boundary="MTWJ_rel_bound_0B"

--MTWJ_rel_bound_0B
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
=09<head>
=09=09<title>My email</title>
=09</head>
=09<body text=3D"#000000" bgcolor=3D"#33ccff" link=3D"#000099" vlink=3D"#99=
0099" alink=3D"#000099" background=3D"cid:MTWJ_cnid_0B_1@makeMIMEembed">
=09=09<h4>Hi all,</h4>
=09=09<table cellpadding=3D"2" cellspacing=3D"2" border=3D"1" width=3D"40" =
align=3D"right">
=09=09=09<tr>
=09=09=09=09<td valign=3D"top">
=09=09=09=09=09<a href=3D"http://www.howtocreate.co.uk/">HowToCreate</a><br=
>
=09=09=09=09=09<a href=3D"http://www.cavinguk.co.uk/">Cavinguk</a><br>
=09=09=09=09=09<a href=3D"http://www.ukcaves.co.uk/">UKCaves</a>
=09=09=09=09</td>
=09=09=09</tr>
=09=09</table>
=09=09<p>
=09=09=09I have been meaning to tell you <b>I, yes, me</b> have been thinki=
ng about
=09=09=09buying<font size=3D"+1" color=3D"#ff6600"> A NEW BIKE!!!</font>
=09=09</p>
=09=09<p>
=09=09=09Any ideas of what design I need?
=09=09</p>
=09=09<hr width=3D"100%" size=3D"1">
=09=09<p>
=09=09=09David
=09=09</p>
=09=09<p>
=09=09=09<font color=3D"#666666">PS, I am using Fran's email today</font>
=09=09</p>
=09</body>
</html>

--MTWJ_rel_bound_0B
Content-Type: image/png
Content-Disposition: inline; filename="hatch.png"
Content-Transfer-Encoding: base64
Content-ID: <MTWJ_cnid_0B_1@makeMIMEembed>

iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAAE/f6/xAAAAK3RFWHRDcmVhdGlvbiBUaW1lAFNh
dCA3IE1hciAyMDA5IDIxOjA0OjEyIC0wMDAwUomIkwAAAAd0SU1FB9kDBxUGIrpFItcAAAAJcEhZ
cwAACxIAAAsSAdLdfvwAAAAEZ0FNQQAAsY8L/GEFAAAABlBMVEWHh4fW1tbkTCNVAAAADklEQVR4
2mNgYGhgaAAAAgYBAVTPwikAAAAASUVORK5CYII=

--MTWJ_rel_bound_0B--

--MTWJ_alt_bound_0B--

--MTWJ_mixed_bound_0B
Content-Type: image/gif
Content-Disposition: attachment; filename="tinyblue.gif"
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAAAAQP///ywAAAAAAQABAEACAUQAOw==

--MTWJ_mixed_bound_0B
Content-Type: image/gif
Content-Disposition: attachment; filename="tinyred.gif"
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAP8AAP///ywAAAAAAQABAEACAUQAOw==

--MTWJ_mixed_bound_0B--
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.