/**
* Send an email with file attached
* www.unexpectedit.com
*/
public function send($fileatt, $from, $to) {
$headers = "From: "."ordermanagement@handpickedcollection.com";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n";
/* PREPARE ATTACHMENT */
$fileatt_type = "application/octet-stream";
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: application/octet-stream;\n" .
" name=\"{$fileatt}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$strto=gmdate("dS M,Y H:i", strtotime($to));
$ok = mail("ignacio@richardmason.net", "Unprocessed orders: $strto", $email_message, $headers);
return($ok);
}
Tags: attachment, email, PHP