note 57315 added to function.mail
| From: | php-general at lists dot php dot net | Date: | Fri, 30 Sep 2005 11:53:42 +0000 |
| Subject: | note 57315 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96043@lists.php.net to get a copy of this message | ||
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;
// ��६ ꫠ��r /> function
mime_mail() {
$this->parts = array();
$this->to = "";
$this->from = "";
$this->subject = "";
$this->body = "";
$this->headers = "";
}
// ꠪ ����
??䮡ࢫ孨?髮⠢ 컫br />
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";
}
// Ϯ��࠱?, ﮱ륤�
⻧?࿠??ꫠ��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();
?>
----
Manual Page -- http://www.php.net/manual/en/function.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57315
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57315&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57315&report=yes
Search -- http://master.php.net/manage/user-notes.php