在PHP代码中添加BCC中的电子邮件地址

时间:2014-03-07 17:13:52

标签: php bcc

我正在试图弄清楚如何在BCC中添加电子邮件地址。 由于我添加了更多“$ headers”来添加盲目的电子邮件地址,因此整个代码不再起作用。

<?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 );

}
?>

2 个答案:

答案 0 :(得分:1)

您还需要在标题的第一行添加换行符:

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 );

}

答案 1 :(得分:1)

您似乎忘记了From标题上的行结尾。

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