为什么通过php邮件发送的密送电子邮件不会被隐藏

时间:2018-02-01 22:08:45

标签: php email bcc

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

$prod = Mage::getModel('catalog/product') -> load($product -> getId());
$productType =  $prod -> getId();
$productVisibility = $prod -> getAttributeSetName();
if($productType === "295")
{
  continue;
}
else
[more code]

所以我有一个convert.exe "input.psd[0]" -resize 1280x-1 "output.jpg" 文件,其中存储了所有电子邮件,逗号彼此分开,如下所示:

// 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.';
}

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

enter image description here

如何才能看到电子邮件发送到哪里?

2 个答案:

答案 0 :(得分:3)

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

让它成为一行:

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

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

答案 1 :(得分: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));