Created
June 1, 2014 15:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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