Skip to content

Instantly share code, notes, and snippets.

@skalnik
Created February 16, 2009 17:26
Show Gist options
  • Save skalnik/65258 to your computer and use it in GitHub Desktop.
Save skalnik/65258 to your computer and use it in GitHub Desktop.
$email_message = "<p style=\"color:red;\">Hello World!</p>";
$headers = "From: $email_from\r\n";
$file = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$file_name = $_FILES['file']['name'];
$f = fopen($file, 'rb');
$raw = fread($f, $_FILES['file']['size']);
fclose($f);
$attachment = chunk_split(base64_encode($raw));
$rand = md5(time());
$boundary = "Multipart-Boundary-$rand";
$headers .= "MIME-Version:1.0\r\n".
"Content-Type: multipart/mixed;\r\n".
" boundary=\"$boundary\"";
$message .= "--$boundary\n".
"Content-Type:text/html; charset=\"iso-8859-1\"\n".
"Content-Transfer-Encoding: 7bit\n\n".
$email_message."\n\n";
$message .= "--$boundary\n".
"Content-Type={$file_type};\n".
" name=\"{$file_name}\"\n".
"Content-Disposition: attachment;\n".
" filename=\"{$file_name}\"\n".
"Content-Transfer-Encoding: base64\n\n".
$attachment."\n\n".
"--$boundary--\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment