note 38801 added to function.mail

From: Date: Wed, 07 Jan 2004 14:07:44 +0000
Subject: note 38801 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-63068@lists.php.net to get a copy of this message
To add an attachment to a mail: <?php function mail_attach($to, $from, $subject, $message, $file) { // $to Recipient // $from Sender (like "email@domain.com" or "Name <email@domain.com>") // $subject Subject // $message Content // $file File (on server) to attach $mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1)); $data = chunk_split(base64_encode(implode("", file($file)))); $header = "From: ".$from."\r\n"; $header.= "To: ".$to."\r\n"; $header.= "MIME-Version: 1.0\r\n"; $header.= "Content-Type: multipart/mixed;\r\n"; $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.= $message."\r\n"; $content.= "--".$mime_boundary."\r\n"; $content.= "Content-Disposition: attachment;\r\n"; $content.= "Content-Type: Application/Octet-Stream; name=\"".$file."\"\r\n"; $content.= "Content-Transfer-Encoding: base64\r\n\r\n"; $content.= $data."\r\n"; $content.= "--" . $mime_boundary . "\r\n"; if(mail($to, $subject, $content, $header)) { return TRUE; } return FALSE; } mail_attach($to, "Sender <sender@address.com>", "Subject", $text, "./mydir/file.jpg"); ?> ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38801 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38801&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38801&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63068) next »