doudeng9425 2018-01-02 16:35
浏览 72
已采纳

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

Below is how I tried to unset all the mail header array by cc and bcc.

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

There are cc, Ccc, CCC, bcc, Bcc and BCC. I know the above solution is not efficient. How can I replace the above code with a shorter code using for-loop?

  • 写回答

1条回答 默认 最新

  • dqsvnsad79721 2018-01-02 16:47
    关注

    You can create an array with all the "cc" and "BCC"s and loop it.

    $items = ["cc","Cc","CC","bcc","Bcc","BCC"];
    
    Foreach($items as $item){
        Unset($message[$item],$message['headers'][$item], $message['params']['headers'][$item]);
    }
    

    Not sure if I got them all or missed one, but you get the point.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用