【问题标题】:I need PHP Mail hide other recipient addresses on multiple email sends我需要 PHP Mail 在多个电子邮件发送中隐藏其他收件人地址
【发布时间】:2020-11-28 11:01:04
【问题描述】:

我有一个 PHP 脚本,它在函数调用中向多个收件人发送电子贺卡(将一组以逗号分隔的电子邮件地址和 mail() 分别发送给每个收件人)。但是,在查看收到的电子邮件时,每个客户都可以看到电子邮件发送到的其他地址,这让我相信它们都是在一封电子邮件中发送的,尽管有单独的 mail() 调用。这是我当前的代码:

$to = "email1@example.com, email2@example.com,email3@example.com";

$subject = "subject";

$message = "This is body";

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= 'From: <'.$from.'>' . "\r\n";

$status =  mail($to,$subject,$message,$headers);

【问题讨论】:

  • 这个 PHPMailer 在哪里?
  • 我用过简单的邮件功能。
  • 您需要创建一个 foreach() 循环并通过电子邮件地址单独运行它,

标签: php phpmailer php-7


【解决方案1】:

您要么需要使用库,例如PHPMailer,然后您可以设置BCC(Blind Carbon Copy),这样他们就看不到其他电子邮件地址。

PHPMailer 具有更多优势,仅举几例:

  • SMTP 支持
  • 附件
  • 防止标头注入攻击

否则你可以循环整个过程并且一次只发送到一个电子邮件地址,但这并不是真正的高效。

【讨论】:

  • 完全正确。 PHPMailer 还提供了如何有效地发送到邮件列表的文档和代码示例。
【解决方案2】:

在邮件功能中添加 null,收件人只能看到发件人

$mrows = $sql->execute("SELECT email FROM email", SQL_RETURN_ASSOC);

$mnum = sizeof ($mrows);  

 // get the email address for who we are sending this email to.
 for ( $mi = 0; $mi < $mnum; ++$mi )
      {
       $email = $mrows [ $mi ] [ "email" ];     
       @$bcc_emails .= "".$email.", ";
      }     
 
 @$bcc_emails .= "".$email.", ";
 $headers .= "BCC: ".$bcc_emails."\n";
 mail(null, $email_subject, $email_text, $headers);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 2020-12-01
    相关资源
    最近更新 更多