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($userf ile));
$file = chunk_split(bas e64_encode($fil e));
$email_boundary = md5(uniqid(time ()));
$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-type: multipart/mixed;boundary= \"$email_bounda ry
\"";
$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($userf ile);
$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@des tinatario.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@des tinatario.it", "Invio", $email_body, $email_headers) ;
but there was no file attached
<?
$userfile = "file.html" ;
$fp = fopen($userfile , "r");
$file = fread($fp, filesize($userf ile));
$file = chunk_split(bas e64_encode($fil e));
$email_boundary = md5(uniqid(time ()));
$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-type: multipart/mixed;boundary= \"$email_bounda ry
\"";
$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($userf ile);
$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@des tinatario.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@des tinatario.it", "Invio", $email_body, $email_headers) ;
but there was no file attached
Comment