0

the code below is used on my site to send e-mails via a contact form. I'd like to add an additional e-mail address on BCC but can't figure out how to to this so your help would be welcome. Many thanks

<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }

  //send email
  mail( "xyz@hhhjkh.com", "New message from: ".$_POST['name'], $_POST['message'], "From:" . $_POST['email'] );

}
?>
Greg
  • 3,025
  • 13
  • 58
  • 106

1 Answers1

0

You can just add a BCC header in the same parameter as the From header:

"From:" . $_POST['email']

becomes:

"From:" . $_POST['email'] . "\r\n" . "BCC:mail@test.com"

See Example #4 on the PHP mail() page. (Or Example #2, though #4 specifically has a BCC header.)

David
  • 208,112
  • 36
  • 198
  • 279