PHPBuilder - Sending Multipart Mime Encoded Email

RSS Twitter

Sending Multipart Mime Encoded Email

by: David McInnis
March 10, 2002

Version: 0.5

Type: Function

Category: HTTP

License: GNU General Public License

Description: This function allows you to send a multi part mime encoded email (HTML and Plain Text). You pass the HTML and TEXT messages in as strings.

// *** Sends and email message based on parameters passed ***//

function send_multiemail ($lc_recipient_email, $lc_recipient_name, $lc_subject, $lc_from_email, $lc_from_name, $lc_sender, $lc_priority, $lc_return, $lc_html, $lc_text)
	// send email
	$boundary = "----=_NextPart_000_" . uniqid("DO_PHP");

	// text
	$lc_message .= "--$boundary\n";
	$lc_message .= "Content-Type: text/plain; \n\tcharset=\"iso-8859-1\"\n";
	$lc_message .= "Content-Transfer-Encoding: 7bit\n";
	$lc_message .= $lc_text . "\n";

	// html
	$lc_message .= "--$boundary\n";
	$lc_message .= "Content-Type: text/html; \n\tcharset=\"iso-8859-1\"\n";
	$lc_message .= "Content-Transfer-Encoding: 7bit\n";
	$lc_message .= $lc_html;

	// final boundary
	$lc_message .= "\n--$boundary--";

	/* recipients */
	$lc_recipient = "$lc_recipient_name <$lc_recipient_email>";

	/* subject */
	$lc_subject = "$lc_subject";

	$lc_headers  = "From: $lc_from_name <$lc_from_email>\n";
	$lc_headers .= "X-Sender: <$lc_sender>\n"; 
	$lc_headers .= "X-Mailer: DataOvation\n"; // mailer
	$lc_headers .= "Return-Path: <$lc_return>\n";  // Return path for errors
	$lc_headers .= "Mime-Version: 1.0\n";
	$lc_headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\n";
	$lc_headers .= "X-Priority: $lc_priority"; // Urgent message!
	mail($lc_recipient, $lc_subject, $lc_message, $lc_headers);
	//end email stuff
	return "";

Comment and Contribute

Your comment has been submitted and is pending approval.

David McInnis



(Maximum characters: 1200). You have characters left.