如何在 PHP 循环中通过数组键 cc 和 bcc 取消设置所有邮件 headers?

How to unset all the mail headers by array key cc and bcc in a loop in PHP?

下面是我如何尝试通过抄送和密件抄送取消设置所有邮件 header 数组。

unset(
  $message['cc'], $message['Cc'], $message['CC'],
  $message['headers']['cc'], $message['headers']['Cc'], $message['headers']['CC'],
  $message['params']['headers']['cc'], $message['params']['headers']['Cc'], $message['params']['headers']['CC'],
  $message['bcc'], $message['Bcc'], $message['BCC'],
  $message['headers']['bcc'], $message['headers']['Bcc'], $message['headers']['BCC'],
  $message['params']['headers']['bcc'], $message['params']['headers']['Bcc'], $message['params']['headers']['BCC']
);

ccCccCCCbccBccBCC。我知道上述解决方案效率不高。如何使用 for-loop?

用更短的代码替换上面的代码

您可以创建一个包含所有 "cc" 和 "BCC" 的数组并循环它。

$items = ["cc","Cc","CC","bcc","Bcc","BCC"];

Foreach($items as $item){
    Unset($message[$item],$message['headers'][$item], $message['params']['headers'][$item]);
}

不确定我是全部收到还是漏掉了,但你明白了。