Sending attachement to Bcc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Sending attachement to Bcc

Post by sulen »

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);

}
}
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Tried...

headers = "From: ".$email_from."\r\n";
$headers .= "Bcc: webmaster@alturacs.com\r\n";

?
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post by sulen »

I did not understand what u meant............i commented that line as it doesnt work but if the line is included it messes up the attachement and doesnt send it to anybody.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well you should separate headers with \r\n and you wern't doing that, so that was the first thing to try, if you tried my suggestion and it still didn't work then we can rule that out and move on to trying something else.
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post by sulen »

I tried that but it still doest work

I am goin crazy with this crap..................
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What version of PHP are you using and on what OS/webserver? (windows, *nix, apache, IIS etc..) ?
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post by sulen »

Version : PHP Version 4.3.2
Webserver : Apache
OS : Linux
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, i'm all out of ideas then, but i suspect malformed headers.
I tend to cheat and use something like phpmailer for sending 'complex' emails.
Post Reply