【问题标题】:Adding e-mail address in BCC in a PHP code在 PHP 代码中在密件抄送中添加电子邮件地址
【发布时间】:2014-04-10 23:23:41
【问题描述】:

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

}
?>

【问题讨论】:

标签: php bcc


【解决方案1】:

您似乎忘记了 From 标头中的行尾。

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

【讨论】:

  • 也谢谢你:)
【解决方案2】:

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

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 2015-07-17
    • 2012-03-20
    相关资源
    最近更新 更多