Hmm, not sure what happened there. I guess I have a video to re-make
Here is the code anyway
<?php
// sends the given meesage to the given email address attaching the given file.
function mail_file($to, $from, $subject, $body, $file){
$boundary = md5(rand());
$headers = array(
'MIME-Version: 1.0',
"From: {$from}",
"Content-Type: multipart/mixed; boundary=\"{$boundary}\""
);
$message = array(
"--{$boundary}",
"Content-Type: text/plain; charset=\"utf-8\"",
"Content-Transfer-Encoding: 7bit",
"",
chunk_split($body),
"--{$boundary}",
"Content-Type: {$file['type']}; name=\"{$file['name']}\"",
"Content-Disposition: attachment; filename=\"{$file['name']}\"",
"Content-Transfer-Encoding: base64",
"",
chunk_split(base64_encode(file_get_contents($file['path']))),
"--{$boundary}--",
);
return mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
}
?>