Skip to content

Instantly share code, notes, and snippets.

@IngmarBoddington
Created June 1, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IngmarBoddington/02aac1ac0d9f84e905f4 to your computer and use it in GitHub Desktop.
Save IngmarBoddington/02aac1ac0d9f84e905f4 to your computer and use it in GitHub Desktop.
Basic function for sending html / txt mixed content email via native php mail() function
function sendMail($toEmail, $fromEmail, $fromName, $replyEmail, $subject, $html = '', $text = '') {
$boundary = "nextPart";
$headers = 'From: '.$fromName.' <'.$fromEmail.'>'."\r\n";
$headers .= 'Reply-To: '.$replyEmail."\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion()."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
//text version
$message = "\n--$boundary\n";
$message .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$message .= $text;
//html version
$message .= "\n--$boundary\n";
$message .= "Content-type: text/html; charset=iso-8859-1\r\n";
$message .= $html;
if (mail($toEmail, $subject, $message, $headers)) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment