简体   繁体   English

用PHP代码在密件抄送中添加电子邮件地址

[英]Adding e-mail address in BCC in a PHP code

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. 由于我添加了更多的“ $ 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 );

}
?>

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

}

It looks like you forgot your line endings on your From header. 好像您忘记了From标头上的行结尾。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM