1

我试图弄清楚如何在密件抄送中添加电子邮件地址。由于我添加了更多“$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 );

}
?>
4

2 回答 2

1

看起来您忘记了From标题中的行尾。

if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
  $headers = "From: $_POST[email]\r\n";
} else {
  $headers = "From: $youremail\r\n";
}
于 2014-03-07T17:15:58.227 回答
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 );

}
于 2014-03-07T17:15:28.587 回答