将密件抄送字段添加到php联系表单 [英] Add BCC field to a php contact form

查看:78
本文介绍了将密件抄送字段添加到php联系表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在我的网站上用于通过联系表发送电子邮件。
我想在密件抄送中添加其他电子邮件地址,但不知道该怎么做,因此欢迎您的帮助。非常感谢

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'] );

}
?>


推荐答案

您只需添加 BCC 标头与 From 标头相同:

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

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

成为:

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

请参见示例#4,在 PHP mail()页面。 (或示例2,尽管#4特别具有 BCC 标头。)

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

这篇关于将密件抄送字段添加到php联系表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆