Based on several different sources, I have compiled the following as my basic HTML email template. Please let me know if I have missed anything important. I am not sure if I am using \n
and \r\n
correctly.
$semi_rand = uniqid();
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
$boundary = "nextPart";
$headers = "From: ".$from."\n";
$headers .= "To: ". $to ."\n";
$headers .= "CC: ". $CC ." \r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: <". $data['from'] .">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative;\n boundary=" . $mime_boundary_header ;
$headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding:base64\r\n";
$body = "
--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
". strip_tags($message) ."
--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding:base64
". chunk_split(base64_encode(
'<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'.
$style.'</head><body>'.$message.'</body></html>' )) ."
--$mime_boundary--";
mail(null,$subject,$body,$headers,"-f".$email);
Questions:
- Will switching
base64_encode()
toquoted_printable_encode()
work or will I also need to convert the string to an 8-bit string somehow? - Should I just remove these extra headers?
- Could/should I use
\r\n\
at every line break, including the ones in the multiline string?