note 52672 added to function.mail

From: Date: Mon, 09 May 2005 13:03:48 +0000
Subject: note 52672 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-89161@lists.php.net to get a copy of this message
Good Example from http://docs.com.ru/php_3.php : Send file.zip on 333@mail.ru . File file.zip inheres beside this php: <?php class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; // ñîçäàåì êëàññ function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } // êàê ðàç ñàìà ôóíêöèÿ äîáàâëåíèÿ ôàéëîâ â ìûëî function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts [] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name ); } // Ïîñòðîåíèå ñîîáùåíèÿ (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"; } // Ïîñûëêà ñîîáùåíèÿ, ïîñëåäíÿÿ âûçûâàåìàÿ ôóíêöèÿ êëàññà 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(); ?> ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52672 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52672&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52672&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52672&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52672&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52672&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52672&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89161) next »