Reputation: 1695
I cannot get this header to show the variable needed for some strange reason. I know its something very slight. I know that this works:
$headers .= 'Bcc: [email protected]' . "\r\n";
Can someone please help me with this. FULL CODE:
<?php
if ($_POST){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$message .= "<hr />Sent from your Website at example.com.";
$to = '[email protected]';
$from = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// THE EMAIL IS NOT SENDING THE SENDER OF THE EMAIL
// the from and bcc do not work as needed!
// More headers, put on double quotes
$headers .= 'From:'.$from."\r\n";
$headers .= 'Bcc: '.$from."\r\n";
// send
if (mail($to,$subject,$message,$headers))
{
echo "Message was successfully sent! $from";
} else {
echo "Something went wrong..";
}
} else {
}
?>
Upvotes: 0
Views: 6042
Reputation: 1
Use this will work perfectly:
$headers .= 'From: "'.$from.'"' . "\r\n";
Upvotes: 0
Reputation: 726
You are missing a dot (period) after your first 'Bcc: '.
it should be
$headers .= 'Bcc: ' . $from . "\r\n";
UPDATE:
You need to use double quotes when using special characters like \r and \n. In your original example code you used double quotes, but I see now with your full code that you're not actually using them, you're using single quotes.
Single quoted strings in PHP show special characters as literals.
So your lines should be
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Bcc: ' . $from . "\r\n";
Upvotes: 3