sending mail with attachment problems
| From: | tony | Date: | Tue, 27 Jan 2004 15:47:34 +0000 |
| Subject: | sending mail with attachment problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-175944@lists.php.net to get a copy of this message | ||
Hi,
i'm trying to send emails with attachment but i get an error
at $file = fread($fp, $att_size);
and i don't understand why, any help is appreciated.
code is below
$subject = $_REQUEST['subject'];
$cc = $_REQUEST['cc'];
$from = $_REQUEST['from'];
$message = $_REQUEST['text'];
$att = $_FILES['attachment'];
$filename = "/home/prog/www/phpmail.txt";
$handle = fopen ($filename, "r");
$fp = fopen($att_name, "r");
$file = fread($fp,$att_size);
$file = chunk_split(base64_encode($file));
$num = md5( time() );
$hdr = "From:$from\r\n";
$hdr .= "CC:$cc\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-type: multipart/mixed; ";
$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 .= "$message\r\n";
$hdr .= "--$num\n";
$hdr .= "Content-type: $att_type; ";
$hdr .= "name=\"$att_name\"\r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"$att_name\"\r\n\n";
$hdr .= "$file\r\n";
$hdr .= "--$num--";
do{
$data = fread($handle, 128);
if (strlen($data) == 0) {
break;
}
mail($data,$subject,"",$hdr);
print "done to $data with attachment";
}while(true);
fclose($handle);