note 57315 deleted from function.mail by mazzanet

From: Date: Fri, 30 Sep 2005 11:58:16 +0000
Subject: note 57315 deleted from function.mail by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96044@lists.php.net to get a copy of this message
Note Submitter: ---- Hi all, This script helped to give the basic idea to send multiple attachment php mail... The following script has some bugs so it will nt giv u output at one shot... To make it work....U need to change following things 1)$multipart = "Content-Type: multipart/mixed; \n boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary"; ***note the '\n' before boundary here 2) instead of generating parts[] array , i have passed the binary encoded message. 3) $mail->add_attachment("$attachment", "file.zip", "application/x-unknown-content-type"); *** when u call add_attachment function, the third parameter should mention the mime type But still to make this script work u really need to check for '\n'. Even if u miss a '\n' , the script doesnt work.. Neways, This script helped me to see the basic skeleton of sending multiple attachment mail Thanks <?php class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; // &#55674;&#56804;&#2412; &#43744;&#55687;&#57122;r /> function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } // &#43050; &#55362;&#56800;&#55618;&#57120; ??&#19361;&#2219;&#23400;?&#39662;&#10274; &#52971;&#59452;br /> function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts [] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name ); } // &#1006;&#55691;&#56366;&#23400;&#22577;&#60321;? (multipart) function build_message($part) { $message = $part["message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; return "Content-Type: ".$part["ctype"].($part["name"]? "; name = \"".$part["name"]."\"" : "")."\nContent-Transfer-Encoding: $encoding\n\n$message\n"; } function build_multipart() { $boundary = "b".md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary"; for($i = sizeof($this->parts)-1; $i>=0; $i--) $multipart .= "\n".$this->build_message($this->parts[$i]). "--$boundary"; return $multipart.= "--\n"; } // &#1006;&#55726;&#57066;&#2097;&#60321;?, &#64433;&#47460;&#57343; &#12007;?&#4064;??&#43744;&#55686;&#56380;br /> function send() { $mime = ""; if (!empty($this->from)) $mime .= "From: ".$this->from. "\n"; if (!empty($this->headers)) $mime .= $this->headers. "\n"; if (!empty($this->body)) $this->add_attachment($this->body, "", "text/plain"); $mime .= "MIME-Version: 1.0\n".$this->build_multipart(); mail($this->to, $this->subject, "", $mime); } } $attachment = fread(fopen("file.zip", "r"), filesize("file.zip")); $mail = new mime_mail(); $mail->from = "my@e-mail.com"; $mail->headers = "Errors-To: [EMAIL=my@e-mail.com]my@e-mail.com[/EMAIL]"; $mail->to = "333@mail.ru"; $mail->subject = "PHP atachment"; $mail->body = "Get your file!"; $mail->add_attachment("$attachment", "file.zip", "Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEASABIAAD/7QT+UGhvdG9zaG"); $mail->send(); ?>

« previous php.notes (#96044) next »