PHP forwarding from HTML Form

I have a Form within my HTML Club Site which works fine. However, as someone new to PHP I am having some difficulty making 2 modifications.

Present Coding:

<?php

$sendTo = “myemail@mysite.com”;

$subject = “Contact from site”;

$headers = “From: " . $_POST[“name”] . “<” . $_POST[“Email”] .”>" . "\r
";

$headers .= "Reply-To: " . $_POST[“eEmail”] . "\r
";

$headers .= "Return-path: " . $_POST[“E-mail”];

$message = "The following information has been submitted by " .$_POST[“name”] . "\r
" . "\r
" . "E-mail Address : " . $_POST[“Email”] . "\r
" . "First Name : " . $_POST[“name1”] . "\r
" . "Last Name : " . $_POST[“name2”] . "\r
" . "Address 1 : " . $_POST[“address1”] . "\r
" . "Address 2 : " . $_POST[“address2”] . "\r
" . "Zip or Post Code : " . $_POST[“post_code”] . "\r
" . "Comments : " . $_POST[“comments”];

mail($sendTo, $subject, $message, $headers);

header( ‘Location: http://www.mysite.com/thanks.html’ ) ;

?>

I would like to send a BCC e-mail to a second recipient. I can send to a second e-mail by changing that first line:

$sendTo = “myemail@mysite.com,myemail2@mysite.com”;

That also works but I can’t get it to BCC:

My second wish is to send the e-mail back to the person filling in the Form, $_POST[“Email”] How is this done?

Any advice would be most appreciated

Although I use the swiftmailer library for email (http://swiftmailer.org/), From the PHP manual on the mail function (http://php.net/manual/en/function.mail.php) it says to send a BCC like:

[COLOR=#0000BB]$headers [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#DD0000]'Bcc: someBCCRecepient@example.com' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#DD0000]"\\r\
"[/COLOR][COLOR=#007700];
[/COLOR]

So your page would look something like:

$sendTo = "myemail@mysite.com";

$subject = "Contact from site";

$headers = "From: " . $_POST["name"] . "<" . $_POST["Email"] .">" . "\\r\
";

$headers .= "Reply-To: " . $_POST["eEmail"] . "\\r\
";
$headers .= 'Bcc:' . $BCCAddress. "\\r\
";

$headers .= "Return-path: " . $_POST["E-mail"];

Now the $BCCAddress could be hardcoded into your PHP page, be pulled from a database, or php session.

It also is a big no-no to trust $_POST data without escaping it you should do something like:

$cleanEmail = htmlentities($_POST["eEmail"]);

You should escape all form data and any Input or Output data. This means POST, GET, Session, and Database. You may also want to look at email form validation and some SPAM protection; even a CAPTCHA (http://www.captcha.net/) would help here.

You can learn more about htmlentities at [URL=“http://php.net/manual/en/function.htmlentities.php”]http://php.net/manual/en/function.htmlentities.php

Hope this helps,
Steve

My second wish is to send the e-mail back to the person filling in the Form, $_POST[“Email”] How is this done?
Sorry missed this…

The mail function returns TRUE if successfully sent so you could do something like:

[COLOR=#0000bb]

if(mail($to, $subject, $message, $headers) == 1){
  //run the mail code again with the person filling the form's email.
  $to      = 'poster@example.com';
 $subject = 'the subject';
 $message = 'some message';
 $headers = 'From: htmlclub@example.com' . "\\r\
" .
    'Reply-To: me@example.com' . "\\r\
" .
    'X-Mailer: PHP/' . phpversion();

  mail($to, $subject, $message, $headers);
} else {
  echo 'There was a problem with your mail, please try again.';
}

[/COLOR]