0

I want to add bcc in my mail function php file.

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/'>";
ochs.tobi
  • 3,214
  • 7
  • 31
  • 52

2 Answers2

0

add in header:

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

for your code:

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

Though not solved then try:

$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);
Rakesh P
  • 438
  • 5
  • 19
  • Not solved yet How can I add bcc in this Line : $to='kriti@vsbhotels.com, contact@vsbhotels.com, verun@vsbhotels.com'; – Rahul Sonker Dec 20 '18 at 07:35
  • 1
    You will get your answer with proper explanation: http://uk3.php.net/manual/en/function.mail.php – Rakesh P Dec 20 '18 at 07:37
  • Can you provide more context such that others can learn from your answer? Please don't do so by posting a link – Nico Haase Dec 20 '18 at 07:47
  • Now this code shows his error This page isn’t working themerakihotel.com is currently unable to handle this request. HTTP ERROR 500 – Rahul Sonker Dec 20 '18 at 08:00
0

Just add BCC:with your email id in headers parameter.

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