sending files attached via mail. what's wrong?

This is a discussion on sending files attached via mail. what's wrong? within the PHP Language forums, part of the PHP Programming Forums category; i wanna send html files (even *.doc) in the body of a mail with this code: <? $userfile = "file....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-04-2003
Agenzia Petracca
 
Posts: n/a
Default sending files attached via mail. what's wrong?

i wanna send html files (even *.doc) in the body of a mail with this code:

<?
$userfile = "file.html";
$fp = fopen($userfile, "r");
$file = fread($fp, filesize($userfile));
$file = chunk_split(base64_encode($file));

$email_boundary = md5(uniqid(time()));
$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-type: multipart/mixed;boundary=\"$email_boundary
\"";
$email_headers .= "X-attachments: $file\n";
$email_headers .= "\r\n\r\n";

$email_body = "-$email_boundary\n";
$email_body .= "Content-type: text/html; charset=iso-8859-1\r\n";
$email_body .= "Content-transfer-encoding: 8bit\r\n\r\n";
$email_body .= "-$email_boundary\r\n";
$filename = basename($userfile);
$email_body .= "Content-type: application/octet-stream; name=$filename\r\n";
$email_body .= "Content-transfer-encoding:base64\r\n\r\n";
$email_body .= $file. "\r\n\r\n";
$email_body .= "--$email_boundary--";

mail("email@destinatario.it", "Invio", $email_headers, $email_body);

?>

unfortunatley, even if the mail arrive, in the body i read only the code of
the file but cannot read it.
WHERE IS THE MISTAKE?
PLEASE HELP!!!!!!

daniele

p.s. i also tried this:
mail("email@destinatario.it", "Invio", $email_body, $email_headers);
but there was no file attached


Reply With Quote
  #2 (permalink)  
Old 11-04-2003
John Dunlop
 
Posts: n/a
Default Re: sending files attached via mail. what's wrong?

Agenzia Petracca wrote:

> i wanna send html files (even *.doc) in the body of a mail with this code:


[Code snipped.]

> WHERE IS THE MISTAKE?


Well, here are some mistakes:

1. Missing linebreak at the end of a header line.

2. Boundaries prefixed with a single hyphen.

3. No data in the "HTML" part.

4. Not providing a text/plain alternative (even worse mistake:
sending so-called HTML mail in the first place).

There are more.

You could read the article referenced from The Manual; or, rather
than reinventing the wheel, you might try a class prewritten for
this purpose, such as M. Lemos' class. (I haven't used it and
therefore can't vouch for it.)
http://www.phpclasses.org/mimemessage

--
Jock
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0