adding Bcc to email

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
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

adding Bcc to email

Post 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");
} 
  
?>
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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";
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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.
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post 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.
Post Reply