mail attachments without PEAR or phpmailer
Posted: Thu Mar 29, 2007 6:10 am
I need to send attachments of WORD files from a form.
I do not have root access, nor path to php.ini, nor any other options but to write this code by hand so we can count these out as the host will not assist. It is 4.31 php without PEAR.
So here goes:
This bit I hope will send off the attachment (above)
but I need to pick up file and chuck it
// DO I NEED TO OPEN AND READ THE ATTACHMENT??
I do not have root access, nor path to php.ini, nor any other options but to write this code by hand so we can count these out as the host will not assist. It is 4.31 php without PEAR.
So here goes:
Code: Select all
$mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1));
$header = "From: $from\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed;";
$header.= " boundary=\"".$mime_boundary."\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= strip_tags($message)."\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: ".$file['type']."; name=\"".$file['name']."\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n";
$content.= "Content-Disposition: attachment\r\n\r\n";
$content.= $file['data']."\r\n";
$content.= "--" . $mime_boundary . "--\r\n";
$mail=mail($to,$subject,$content,$header,"-f$from");
if (!$mail) return false;
else return true;
}but I need to pick up file and chuck it
Code: Select all
//Attachment data
$file['name'] //OK I can get that
$file['type'] //OK I can get that
$file['data']=chunk_split(base64_encode($row[2]),76);
$file['data']=preg_replace("/\r?\n|\r/","\r\n",$file['data']);
$mail=sendmailattachment($to,$subject,$message,$from,$file);
if($mail) echo "success";
else echo "failure";