I have a mail script to send attachments that works perfectly when the addreses are in the to: field. But if the same addresses are in the bcc: it mails the attachment as garbled text along with the body of the email. I am also pasting my code. Any help will be appreciated. Thanks
<?php
//connecting to the database
@ $db = mysql_pconnect("localhost", "root", "dbstuff3r");
//connection error
if(!$db)
{
echo "error could not connect to the database. please try again later";
exit;
}
//selecting database
mysql_select_db("axis");
$sql = "select * from email";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
for($i=0; $i <$numrows; $i++)
{
$row = mysql_fetch_array($result);
$email=$row[0];
if($_FILES["fileatt"] != NULL)
{
$fileatt_type = "application/octet-stream"; //File Type
$email_from = "webmaster@alturacs.com"; // Who the email is from
$email_subject = $sub; // The Subject of the email
$email_message = $mssg; // Message that the email has in it
$email_to = $email; // Who the email is too
$headers = "From: ".$email_from;
//$headers .= "Bcc: webmaster@alturacs.com\n";
$file = fopen($_FILES["fileatt"]["tmp_name"],"rb");
$data =
fread($file,filesize($_FILES["fileatt"]["tmp_name"]));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-partmessage in
MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
//$email_message = $email_message.$email_txt;
$ok = @mail($email_to, $email_subject, $email_message, $headers);
}
}
?>
Sending attachement to Bcc
Moderator: General Moderators