Re: mail with attachment
| From: | Dre | Date: | Wed, 08 Dec 2004 16:16:04 +0000 |
| Subject: | Re: mail with attachment | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203733@lists.php.net to get a copy of this message | ||
Thanks Manuel, I will check the class
and here is the code of the mail sending script
//======================================================
<?php
$att_name = $_POST['att'];
echo $att_name;
$att_size = filesize($att_name);
$handle= fopen($att_name, "r");
$file = fread($handle, $att_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
$hdr = "From:"."name@excite.com\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "Content-Transfer-Encoding: 7bit\r\n\n";
$hdr .= "boundary=$num\r\n";
$hdr .= "--$num\r\n";
$hdr .= "Content-Type: text/plain\r\n";
$hdr .= "Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .= $_POST['content']."\r\n";
$hdr .= "--$num\n";
$hdr .= "Content-Type: $att_type; ";
$hdr .= "name=\"".$_POST['att']."\"\r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"".$_POST['att']."\"\r\n\n";
$hdr .= "$file\r\n";
$hdr .= "--$num--";
if(mail( "another_name@yahoo.com", $_POST['re'], $_POST['content'],
$hdr))
{echo "done";}
else
{echo "shit";}
fclose($handle);
?>
//======================================================
"Manuel Lemos" <mlemos@acm.org> wrote in message
news:41B6FF9F.1060904@acm.org...
> Hello,
>
> Dre wrote:
> > I'm trying to send a mail with attachment, using mail() fucntion ..
> > the mail is sent with the attached file, but when I open my mail box to
> > check the mail I sent using my script, I find the normal text contents
and
> > the attachment displayed as text too !!!
> > ex. if I attached a document, it will not be just attached when I open
the
> > mail, it will be displayed as text.
> > I'm using multipart MIME
>
> You are probably doing something wrong but without seeing the source of
> your code, it is hard to tell what is the problem.
>
> Anyway, you may want to try this class that is capable of composing and
> sending messages with as many attachments as you want and works properly:
>
> http://www.phpclasses.org/mimemessage
>
>
> --
>
> Regards,
> Manuel Lemos
>
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
>
> PHP Reviews - Reviews of PHP books and other products
> http://www.phpclasses.org/reviews/
>
> Metastorage - Data object relational mapping layer generator
> http://www.meta-language.net/metastorage.html