0

Hi i am trying to add BCC to mail function but it does not works. can anybody please help??? Here my code.

<?php 
     if(isset($_REQUEST['submit'])){
     $cleanedFrom = $_POST['mailtxt'];
      $to ='abcd@abc.com'; 
        $subject = 'Booking Form';
        $headers = "From: " . $cleanedFrom . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        $message= '<html><body>';
        $message .= "</table>";
        $message .= "</body></html>";
        $headers .=  "BCC: abc@abc.com;\r\n";
        $send =    mail($to, $subject, $message, $headers);
        $send =    mail ("info@visitkullumanali.com", $subject, $message, $headers);
    if($send)
    {
        echo "<script> window.location = 'wwww.mysite.com' </script>";}
    else
    {
        echo "<script> window.location = 'index.html' </script>";
    }
 }     

?>

  • You'd probably be better off using [`PHPMailer`](https://github.com/PHPMailer/PHPMailer) that was designed for this kind of thing. – Darren Jan 28 '15 at 07:01
  • Have you tried `$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";` no semicolon after address...etc? This is a copy from the manual – Rasclatt Jan 28 '15 at 07:02
  • thanks for response i am trying the same – Abhishek Dubey Jan 28 '15 at 07:04
  • 1
    BTW. This program is open for email-injection, because you use the posted value directly in your email header. Do something like: `if ( preg_match( "/[\r\n]/", $cleanedFrom )) die('injection detected');` – Mario A Jan 28 '15 at 07:05

3 Answers3

1
    $headers .=  "BCC: abc@abc.com;\r\n";

Remove that extra ; from Bcc value

    $headers .=  "Bcc: abc@abc.com\r\n";
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • 1
    Your code which you posted as an answer still has the same issue. That is why it is not working. Remove that `;` after the email address – Hanky Panky Jan 28 '15 at 07:21
0

Try like this:

$headers .= 'Bcc: abc@abc.com' . "\r\n";

REFERENCE

Priyank
  • 3,778
  • 3
  • 29
  • 48
0

You are missing an important point:

If you want BCC add the receiver via "To:" but not to the headers. People only see who also got the mail via the header information. So you are good to go by adding it via "To:"

Michael Leiss
  • 5,395
  • 3
  • 21
  • 27