/ Published in: PHP
URL: http://dev-tips.com/featured/send-hassle-free-and-dependable-html-emails-with-php
Expand |
Embed | Plain Text
function htmlmail($to, $subject, $message, $headers = NULL) { $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}\n\n"; $newmessage = "This is a multi-part message in MIME format."; $newmessage .= "\n\n--{$mime_boundary}\n"; $newmessage .= "Content-type: text/plain;charset=utf-8\n\n"; $newmessage .= "\n\n--{$mime_boundary}\n"; $newmessage .= "Content-type: text/html;charset=utf-8\n\n"; // prepended HTML $newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">'; // HTML message that was passed to this function $newmessage .= $message; // appended HTML $newmessage .= '</td></tr></table></td></tr></table></body>'; }
Comments
Subscribe to comments
You need to login to post a comment.

i get garbage mime text all over when i receive the mail. why is that?
ok i resolved it. the garbage came from this statement -> $headers .= "\nMessage-ID: \n";
from how i see it. we need to remove that statement. one more thing the function is not dynamic. cause if you need an html based message you will need to have a separate plain message at the same time. the parameter for message is wrong, it should have two paramters for message, htmlmessage and plainmessage for it to have a custom look for each type.