Form to email - add 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
trillodigital
Forum Newbie
Posts: 3
Joined: Thu Jan 13, 2011 2:28 pm

Form to email - add BCC

Post by trillodigital »

Hi,

Please could somebody help. I need my form to send an email to a BCC email address. Here's my current code. It works well, but without the BCC function.

Code: Select all

<?php

// get posted data into local variables
$EmailFrom = "Enquiry";
$EmailTo = "robin@trillodigital.co.uk";
$Subject = "Maria Watt Foundation website enquiry";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email']));
$telephone = Trim(stripslashes($_POST['telephone'])); 
$comments = Trim(stripslashes($_POST['comments'])); 

// validation
if (strtolower($_POST['code']) != 'mwf') {die('Sorry, you have entered the wrong code. This measure is in place to prevent spam via this website. Please go back and enter the correct code.');}

$validationOK=true;
if (Trim($email)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/error.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/error.html\">";
}
?>
Thanks in advance!
Last edited by Benjamin on Thu Jan 13, 2011 5:14 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Form to email - add BCC

Post by superdezign »

It's part of the e-mail headers. You have the "From:" header already. I believe the header for blinded carbon copy is "Bcc:". Be careful, though. Many mail applications will automatically flag messages that have "Bcc:" headers as spam.
Post Reply