RE: [PHP] problems with attachment to email for mail() function
| From: | Dave | Date: | Wed, 05 Jun 2002 13:36:31 +0000 |
| Subject: | RE: [PHP] problems with attachment to email for mail() function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100692@lists.php.net to get a copy of this message | ||
anyone on this...
a few have suggested "install this class" and so forth. That is not the point.
the goal is to correctly format and encode the simple message with attachment so
we can customize things from there. The classes available for this are great,
but defeat the purpose of understanding.
looking forward to comments or suggestions.
Dave
>-----Original Message-----
>From: Dave [mailto:dave@hawk-systems.com]
>Sent: Tuesday, June 04, 2002 5:45 PM
>To: php-general@lists.php.net
>Subject: [PHP] problems with attachment to email for mail() function
>
>
>have a form where user uploads "attachment" and provides email address and a
>brief note regarding the attachment. The below script should grab all that and
>email the note with the attachment to our target user.
>
>Email appears with text portion and attachment icon, but no attachment (Outlook
>2000). In viewing the email prior to delivery to the client, it appears to be
>formatted correctly. The following is the email script, and below that the
>headers from the email.
>
>if \n is replaced with \r\n then no attachment flag appears, otherwise same
>problem
>
>help or insight appreciated.
>
>Dave
>
>>> php file code
>
><?php
># $from, $to, $body, and $attachment are provided in the previous form
>$sig = "\n--\nWebsite Mailer\n";
>$body .= $sig;
>$headers = "From: $from\n";
>$boundary = "=====WSM." . md5(uniqid(time())) . "=====";
>$headers .= "MIME-Version: 1.0\n";
>$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$boundary\"\n\n";
>$str = "--$boundary\n";
>$str .= "Content-Type: text/plain;\n\tcharset=\"us-ascii\"\n";
>$str .= "Content-Transfer-Encoding: 7bit\n\n";
>$str .= "$body\n\n";
>$fp = fopen($attachment, "rb");
>$data = fread($fp, filesize($attachment));
>$data = chunk_split(base64_encode($data),76,"\n");
>fclose($fp);
>$str .= "--$boundary\n";
>$str .= "Content-Type:
>".$attachment_type.";\n\tname=\"".$attachment_name .
>"\"\n";
>$str .= "Content-Transfer-Encoding: base64\n";
>$str .= "Content-Disposition: attachment; \n\tfilename=\"".$attachment_name .
>"\"\n\n";
>$str .= $data;
>$str .= "--$boundary--\n";
>$body = $str;
>
>if(mail($to, $subject, $body, $headers)){
> $status.='<br>Successfully sent.';
>}else{
> $status.='<br>An error occurred while sending.';
>}
>?>
>
>
>>>email header info
>
>Return-Path: <test@server.com>
>Delivered-To: test@server.com
>Received: (qmail 96549 invoked by uid 81); 4 Jun 2002 21:45:49 -0000
>Date: 4 Jun 2002 21:45:49 -0000
>Message-ID: <20020604214549.96548.qmail@server.com>
>To: test@server.com
>Subject: test@server.com
>From: test@server.com
>MIME-Version: 1.0
>Content-Type: multipart/mixed;
> boundary="=====WSM.38ef75d9c66623ee87e302bad63e79b3====="
>
>
>
>--=====WSM.38ef75d9c66623ee87e302bad63e79b3=====
>Content-Type: text/plain;
> charset="us-ascii"
>Content-Transfer-Encoding: 7bit
>
>test
>test
>test
>--
>Website Mailer
>
>
>--=====WSM.38ef75d9c66623ee87e302bad63e79b3=====
>Content-Type: application/octet-stream;
> name="FixKlez.com"
>Content-Transfer-Encoding: base64
>Content-Disposition: attachment;
> filename="FixKlez.com"
>
>TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>AAAA+AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1v
>ZGUuDQ0KJAAAAAAAAABo6XodLIgUTiyIFE4siBROV5QYTi+IFE5Dlx9OJogUTq+UGk43iBROQ5ce
>TluIFE5VqR9OHogUTiyIFU6GiRROTpcHTj2IFE4siBROJIgUTiqrH04oiBRO644STi2IFE5SaWNo
>LIgUTgAAAAAAAAAAAAAAAAAAAABQRQAATAEDAL9J4zwAAAAAAAAAAOAADwELAQYAABACAAAgAAAA
><clipped>
>DBt6MUOTCWeZFsi39DQGvapqsVo/VLIKnbrS15vO5+7fIzhl+Kjhha8azcbokj7NTTK6cF6Dy8Qn
>4LceXyJzQT9bstNNJJT56sz9XJ8lzOFwcv/hpgK2f3QNPSrjU7PKYlerj0kSUpE9DZJqpi+stPFm
>GKrmkNx1Pzv1jBXgMX+r4g7Jz5dnbpgg3tAZMTHHROCAyWsW1JWeaZ6zFSh+7zFodgkbOjZ7hKUy
>nAXiZ0/Z+I+w4fmUwZuJ9kjixNM6MHWSTzVXrBG5XCLm6mEcSGThGP4BUA5wN54K2ace0SA0r9x/
>PsT0J3BGtQ==
>--=====WSM.38ef75d9c66623ee87e302bad63e79b3=====--
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>