【问题标题】:why bcc emails sent via php mail are not hidden为什么不隐藏通过 php 邮件发送的密件抄送电子邮件
【发布时间】:2018-07-12 08:35:20
【问题描述】:

我正在尝试通过密件抄送发送电子邮件,我原以为它们是隐藏的,但似乎没有。也许我的代码不正确?

// grab all emails from txt file
$myfile = fopen("database-email.txt", "r") or die("Unable to open file!");
$allEmails = fread($myfile,filesize("database-email.txt"));
fclose($myfile);

$afzender = "noreply@wisselslag.nl";

$to = 'pj.maessen41@live.nl';

$subject = 'Nieuwsbrief de Wisselslag';

$headers = "From: " . $afzender . "\r\n";   
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: " . $allEmails  . "\r\n";

if (mail($to, $subject, $message, $headers)) {
  echo 'Bericht is verstuurd!';
} else {
  echo 'There was a problem sending the email.';
}

所以我有一个 database-email.txt 文件,其中存储了所有电子邮件,逗号彼此分隔,如下所示:

joey.tims@gmail.com,
j.maessen@online.nl,
john.doe@live.nl,
diana.johnson@hotmail.com,

发送到我的 gmail 帐户时,我可以看到:

这怎么可能我可以看到电子邮件也发送到哪里?

【问题讨论】:

  • $afzender 有值吗?
  • $afzender = "noreply@wisselslag.nl;
  • 电子邮件的收件人始终可以看到“收件人”和“抄送”列表。只有“密件抄送”列表被隐藏
  • 是的,应该隐藏密件抄送。但我可以看到整个密件抄送列表
  • 您的问题似乎是文件中的换行符导致第一个地址之后的任何地址被放置在电子邮件正文中。只需删除换行符

标签: php email bcc


【解决方案1】:

电子邮件列表不应有换行符。

一行:

$allEmails = str_replace(array("\n","\r"), '', $allEmails);

// joey.tims@gmail.com, j.maessen@online.nl, john.doe@live.nl, diana.johnson@hotmail.com

【讨论】:

  • 这真的很有道理!很棒的解决方案。我现在明白我做错了什么。现在效果很好。谢谢@Ben
【解决方案2】:

正如我在评论中提到的,任何收件人列表都不应包含换行符。

我会将您的文件格式更改为单行

joey.tims@gmail.com,j.maessen@online.nl,john.doe@live.nl,diana.johnson@hotmail.com

我也会使用file_get_contents() 而不是fopen / fread


或者,将您的电子邮件地址存储在每一行中,不要使用逗号,例如

joey.tims@gmail.com
j.maessen@online.nl
john.doe@live.nl
diana.johnson@hotmail.com

并使用file()implode()

$allEmails = implode(',' file(__DIR__ . '/database-email.txt',
        FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));

【讨论】:

    猜你喜欢
    • 2012-03-20
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2020-10-10
    • 2013-06-08
    相关资源
    最近更新 更多