如何在邮件功能php中添加密件抄送

时间:2018-12-20 07:22:58

标签: php email bcc

我想在邮件功能php文件中添加密件抄送。

if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['message'])){
    if(!empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['email']) && !empty($_POST['phone']) && !empty($_POST['message'])){
        $fname = $_POST['fname'];
        $lname = $_POST['lname'];
        $phone = $_POST['phone'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            echo'Please feel valid email';
        }
        else {
            $to='kriti@vsbhotels.com, contact@vsbhotels.com, verun@vsbhotels.com';
            $body = $fname."\n". $lname."\n" . $phone."\n" . $email."\n" . $message;
            if(mail($to , $fname." ".$lname , $body ,'From: response@themerakihotel.com')) {
                header('Location: thank-you.html');
                exit();
            }
            else {
                echo "Something went wrong!";
            }
        }
    }
    else {
        echo 'Please Fill All Inputs';
    }
}
else {
    echo 'not okk';
}
echo "<meta http-equiv='refresh' content='0; url=http://merakihotels.in/demo/'>";

2 个答案:

答案 0 :(得分:0)

添加标题:

$headers[] = 'Bcc: someone@example.com';

输入您的代码

mail($to , $fname." ".$lname , $body ,'From: response@themerakihotel.com' . "\r\n" . 'Bcc: someone@example.com')

尽管无法解决,然后尝试:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: FromName<from@example.com>' . "\r\n";
$headers .= 'BCC: Someone<someone@example.com>' . "\r\n";

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

答案 1 :(得分:0)

只需在BCC:with your email id参数中添加headers

$headers="From: response@themerakihotel.com\r\n";
$headers.="BCC:WRITE HERE YOUR EMAIL ID";
mail($to , $fname." ".$lname , $body ,$headers);