Page 1 of 1

adding Bcc to email

Posted: Wed Nov 03, 2004 8:13 am
by juline
Hi folks,

i have a script that attaches a file which has been uploaded to the server and send it to an email-adress, but i couldnt figure out how to add an Bcc to this script. i tried many variations but wouldnt work with that script. can someone help me please ?


Code: Select all

<?php

.....
//here are the posted variables from html site
	$name = $HTTP_POST_VARS['name'];
......	
	$uploaddir = 'uploads/'; 
	$filename=$_FILES['file']['name']; 
  
	if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir."$filename")) 
	{ 
       
    $att=fopen("uploads/$filename", r); 
    $size=filesize("uploads/$filename"); 
    $attfile=fread($att,$size); 
    $att_email=chunk_split(base64_encode($attfile)); 
    fclose($att); 
    
    $To="test@test.com"; 
    $Subject = "Something"; 
    $Message = "blablablabldblabdfafd";
	 
   $file_name = "uploads/$filename"; 
   $file_nameMail = "uploads/$filename"; 
    
   $Header = "From: ".$name." ".$surname." <".$email.">"; 
   
   $bound = strtoupper(md5(uniqid(time()))); 
   $Header .= "\n"; 
   $Header .= "MIME-Version: 1.0"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: multipart/mixed; boundary=$bound"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";
   $Header .= "Content-Type: text/html; charset=iso-8859-1";
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= $Message; 
   $Header .= "\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";  
   $Header .= "Content-Type: $file_type"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: $file_type; name=$DateinameMail"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: base64"; 
   $Header .= "\n"; 
   $Header .= "Content-Disposition: attachment; filename=$file_nameMail"; 
   $Header .= "\n\n"; 
   $Header .= chunk_split(base64_encode(fread(fopen($filename, "r"), filesize($filename)))); 
   $Header .= "\n"; 
   $Header .= "--$bound--"; 
 
    
   mail ($To, $Subject, "", $Header);
   require ("thanx.html");
} 
  
?>

Posted: Wed Nov 03, 2004 9:20 am
by Wayne
change your $Header line to something like this and add in all the headers you need

Code: Select all

$Header .= "From: ".$name." ".$surname." <".$email.">\n"; 
$Header .= "cc:me@y.com\n";
$Header .= "bcc:x@y.com, a@b.net\n";

Posted: Wed Nov 03, 2004 9:30 am
by juline
Wayne wrote:change your $Header line to something like this and add in all the headers you need

Code: Select all

$Header .= "From: ".$name." ".$surname." <".$email.">\n"; 
$Header .= "cc:me@y.com\n";
$Header .= "bcc:x@y.com, a@b.net\n";
thanx for reply, but its not working. i mean yes it is sending the mail to bcc but not the attachement

Posted: Wed Nov 03, 2004 9:38 am
by lostboy
juline,

do you check the mime type of the attachment at all? If the code is as above, its open to abuse by allowing users to send viruses and trojans (via an exe attachment)

I would recommend a check on the mime type and limit it to only a certain set of types if possible.

Posted: Wed Nov 03, 2004 9:41 am
by juline
lostboy wrote:juline,

do you check the mime type of the attachment at all? If the code is as above, its open to abuse by allowing users to send viruses and trojans (via an exe attachment)

I would recommend a check on the mime type and limit it to only a certain set of types if possible.
lostboy,

well, i have to have it open, cause i cant let only docs or txt through. there will be any kind of files send through this. but thank you very much for this hint dear.