问题
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'] );
}
?>
回答1:
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.)
来源:https://stackoverflow.com/questions/19078798/add-bcc-field-to-a-php-contact-form