0

Need to send a BCC copy to a user2@gmail.com Not familiar with PHP and I'm missing something.

<?php   
if(empty($_POST['name2']) || empty($_POST['email2']) || empty($_POST['message2']))
{
    return false;
}

$name2 = $_POST['name2'];
$email2 = $_POST['email2'];
$message2 = $_POST['message2'];

$to = 'user1@gmail.com'; // Email submissions are sent to this email

// Create email 
$email_subject = "Message from Website;
$email_body = "You have received a new message. \n\n".
              "Name2: $name2 \nEmail2: $email2 \nMessage2: $message2 \n";
$headers = "From: user1@gmail.com\n";
$headers .= "Reply-To: $email2";
$headers .= "Bcc: user2@gmail.com" . "\r\n";

mail($to,$email_subject,$email_body,$headers); // Post message
return true;            
?>
Daniel Barton
  • 39
  • 1
  • 9
  • Is `$email_subject = "Message from Website;` intentional? – Dave Chen Jul 12 '15 at 20:07
  • 1
    possible duplicate with: http://stackoverflow.com/questions/9525415/php-email-sending-bcc what you sure miss is a closing " before the semicolon in line: $email_subject = "Message from Website; – wgitscht Jul 12 '15 at 20:08
  • I did read though postings on on the subject here but none seemed to directly answer this; with my basic understanding anyway. Added in the closing ", thanks. – Daniel Barton Jul 12 '15 at 20:39

1 Answers1

1

at the end of any $header line fix that end with "\r\n"

$headers = "From: user1@gmail.com\r\n";
$headers .= "Reply-To: $email2\r\n";
$headers .= "Bcc: user2@gmail.com\r\n";

try now

Nomad Webcode
  • 816
  • 5
  • 9