Revision: 22362
Updated Code
at January 11, 2010 03:14 by ginoplusio
Updated Code
function mail_file( $to, $subject, $messagehtml, $from, $fileatt, $replyto="" ) { $ext = strrchr( $fileatt , '.'); $fileatttype = ""; if ($ext == ".doc") $fileatttype = "application/msword"; if ($ext == ".jpg") $fileatttype = "image/jpeg"; if ($ext == ".gif") $fileatttype = "image/gif"; if ($ext == ".pdf") $fileatttype = "application/x-pdf"; if ($fileatttype=="") $fileatttype = "application/octet-stream"; $file = fopen($fileatt, "rb"); $data = fread($file, filesize( $fileatt ) ); fclose($file); $content = chunk_split(base64_encode($data)); $uid = md5(uniqid(time())); $headers = "From: $from "; if ($replyto) $headers .= "Reply-To: ".$replyto." "; $headers .= "MIME-Version: 1.0 "; $headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\" "; $headers .= "This is a multi-part message in MIME format. "; $headers .= "--".$uid." "; $headers .= "Content-type:text/html; charset=iso-8859-1 "; $headers .= "Content-Transfer-Encoding: 7bit "; $headers .= $messagehtml." "; $headers .= "--".$uid." "; $headers .= "Content-Type: ".$fileatttype."; name=\"".basename($fileatt)."\" "; $headers .= "Content-Transfer-Encoding: base64 "; $headers .= "Content-Disposition: attachment; filename=\"".basename($fileatt)."\" "; $headers .= $content." "; $headers .= "--".$uid."--"; return mail( $to, $subject, strip_tags($messagehtml), str_replace(" ","\n",$headers) ) ; }
Revision: 22361
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 11, 2010 02:52 by ginoplusio
Initial Code
function mail_file( $to, $subject, $messagehtml, $from, $fileatt, $replyto="" ) { $ext = strrchr( $fileatt , '.'); $fileatttype = ""; if ($ext == ".doc") $fileatttype = "application/msword"; if ($ext == ".jpg") $fileatttype = "image/jpeg"; if ($ext == ".gif") $fileatttype = "image/gif"; if ($ext == ".pdf") $fileatttype = "application/x-pdf"; if ($fileatttype=="") $fileatttype = "application/octet-stream"; $file = fopen($fileatt, "rb"); $data = fread($file, filesize( $fileatt ) ); fclose($file); $content = chunk_split(base64_encode($data)); $uid = md5(uniqid(time())); $headers = "From: $from "; if ($replyto) $headers .= "Reply-To: ".$replyto." "; $headers .= "MIME-Version: 1.0 "; $headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\" "; $headers .= "This is a multi-part message in MIME format. "; $headers .= "--".$uid." "; $headers .= "Content-type:text/html; charset=iso-8859-1 "; $headers .= "Content-Transfer-Encoding: 7bit "; $headers .= $messagehtml." "; $headers .= "--".$uid." "; $headers .= "Content-Type: ".$fileatttype."; name=\"".basename($fileatt)."\" "; // use different content types here $headers .= "Content-Transfer-Encoding: base64 "; $headers .= "Content-Disposition: attachment; filename=\"".basename($fileatt)."\" "; $headers .= $content." "; $headers .= "--".$uid."--"; return mail( $to, $subject, strip_tags($messagehtml), str_replace(" ","\n",$headers) ) ; }
Initial URL
http://www.barattalo.it/2010/01/10/sending-emails-with-attachment-and-html-with-php/
Initial Description
Function to send HTML emails with an attachment in PHP. Notes and info at the above url!
Initial Title
Sending emails with attachment and HTML with PHP
Initial Tags
Initial Language
PHP