Adding e-mail address in BCC in a PHP code

非 Y 不嫁゛ 提交于 2019-12-31 04:29:11

问题


I'm trying to figure out how to add an e-mail address in BCC. Since I added more "$headers" to add the blinded e-mail address, the entire code doesn't function anymore.

<?php
// put your email address here
$youremail = 'xxx@xxx.it';

// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == ''){


// prepare message 
$body = "Nuovo messaggio dal sito web :

Nome:  $_POST[name]
Azienda:  $_POST[company]
Telefono:  $_POST[phone]
Email:  $_POST[email]
Messaggio:  $_POST[message]";

if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
  $headers = "From: $_POST[email]";
} else {
  $headers = "From: $youremail";
}
$headers .= "Bcc: yyy@yyy.com\r\n";

mail($youremail, 'Richiesta Informazioni dal Sito Web', $body, $headers );

}
?>

回答1:


You need to add line breaks to the first line of your headers too:

if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
  $headers = "From: $_POST[email]\r\n";
} else {
  $headers = "From: $youremail\r\n";
}
$headers .= "Bcc: yyy@yyy.com\r\n";

mail($youremail, 'Richiesta Informazioni dal Sito Web', $body, $headers );

}



回答2:


It looks like you forgot your line endings on your From header.

if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
  $headers = "From: $_POST[email]\r\n";
} else {
  $headers = "From: $youremail\r\n";
}


来源:https://stackoverflow.com/questions/22256434/adding-e-mail-address-in-bcc-in-a-php-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!