Last active
December 19, 2015 14:49
-
-
Save ccagle8/5971844 to your computer and use it in GitHub Desktop.
Simple HTML email formatting with sendmail.
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
<?php | |
function sendmail($to,$subject,$message,$from='[email protected]', $format = true) { | |
if($format) { | |
$message = email_template($message); | |
} | |
$headers = "From: ".$from . PHP_EOL; | |
$headers .= "Reply-To: ".$from . PHP_EOL; | |
$headers .= "Return-Path: ".$from . PHP_EOL; | |
$headers .= "MIME-Version: 1.0" . PHP_EOL; | |
$headers .= "Content-type: text/html; charset=UTF-8" . PHP_EOL; | |
if( mail($to,'=?UTF-8?B?'.base64_encode($subject).'?=',"$message",$headers) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function email_template($message) { | |
$data = ' | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > | |
<style> | |
table td p {margin-bottom:15px;} | |
</style> | |
</head> | |
<body style="padding:0;margin:0;font-family:arial, \'helvetica neue\', helvetica, serif" > | |
<table cellpadding="0" cellspacing="0" border="0" align="center" width="100%" style="padding: 0 0 35px 0; background: #f3f3f3;"> | |
<tr> | |
<td align="center" style="margin: 0; padding: 0;padding-top:20px;"> | |
<center> | |
<table border="0" cellpadding="0" cellspacing="0" width="480"> | |
<tr> | |
<td style="border-radius:5px;background:#fff;border:1px solid #e1e1e1;border-top:4px solid #e1e1e1;font-size:13px;font-family:arial, helvetica, sans-serif;padding:20px;line-height:22px;color:#333;" > | |
'.$message.' | |
</td> | |
</tr> | |
<tr> | |
<td style="padding-top:10px;font-size:10px;color:#aaa;line-height:14px;font-family:arial, \'helvetica neue\', helvetica, serif" > | |
<p class="meta">© '.date('Y').' YourCompany, LLC.</p> | |
</td> | |
</tr> | |
</table> | |
</center> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> | |
'; | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment