RE: [PHP] Re: Sending letter with attaching of the file
| From: | Rudolf Visagie | Date: | Thu, 13 Dec 2001 15:24:34 +0000 |
| Subject: | RE: [PHP] Re: Sending letter with attaching of the file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-77599@lists.php.net to get a copy of this message | ||
Here is a function I use that might help:
function mail_attachment ($to, $subject, $message, $addr_from, $attachment,
$filename) {
/*
This function sends an e-mail with a file attachment using the
standard
PHP mail function with parameters $to, $subject and $message.
The $attachment parameter is a string with the attachment file
content
which will be named $filename.
Author: Rudolf Visagie (adapted from PHP Developers Cookbook by
Sterling Hughes)
*/
$boundary = "b".md5(uniqid(time()));
$mime = "From: $addr_from\r\n";
$mime .= "Reply-To: $addr_from\r\n";
$mime .= "X-Mailer: Digital Healthcare Solutions\r\n";
$mime .= "X-Sender: $addr_from\r\n";
$mime .= "Content-type: multipart/mixed; ";
$mime .= "boundary = $boundary\r\n\r\n";
$mime .= "This is a MIME encoded message.\r\n\r\n";
// First the regular message
$mime .= "--$boundary\r\n";
$mime .= "Content-type: text/plain\r\n";
$mime .= "Content-Transfer-Encoding: base64";
$mime .= "\r\n\r\n".chunk_split(base64_encode($message))."\r\n";
// Now the attachment
$mime .= "--$boundary\r\n";
$mime .= "Content-type: text/plain\r\n";
$mime .= "Content-Transfer-Encoding: base64\r\n";
$mime .= "Content-Disposition: attachment; ";
$mime .= "filename = ".chr(34).$filename.chr(34);
$mime .= "\r\n\r\n".chunk_split(base64_encode($attachment))."\r\n";
$mime .= "--$boundary--";
mail ($to, $subject, "", $mime);
}
Rudolf Visagie
Principal Software Developer
Digital Healthcare Solutions
Tel. +27(0)11 266 6946
Fax. +27(0)11 266 5080
Cell: +27(0)82 895 1598
E-mail: rudolf@dhsolutions.co.za
-----Original Message-----
From: Jeremy Reed [mailto:jreed@pronet-usa.com]
Sent: 13 December 2001 05:22
To: php-general@lists.php.net
Subject: [PHP] Re: Sending letter with attaching of the file
You cannot attach a file using the mail() function in PHP. You will have to
use a SMTP PHP class or another MIME enabled class to use attachments.
Jeremy
"Alexandr Klaus" <klaus@mail.khb.ru> wrote in message
news:20011213015222.53100.qmail@pb1.pair.com...
> Help me !
>
> For sending a letter I using the mail function in PHP.
> How send the letter with attached file?
>
> --
> Alexandr Klaus
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net