Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created June 17, 2011 17:55
Show Gist options
  • Save jwoertink/1031902 to your computer and use it in GitHub Desktop.
Save jwoertink/1031902 to your computer and use it in GitHub Desktop.
function sendAttachmentEmail($message,$from,$email,$subject, $pdfdoc) {
$separator = md5(time());
$filename = date("m-d-Y-")."questionnaire.pdf";
$eol = PHP_EOL;
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($email, $subject, "", $headers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment