PHP Mail通过多个函数调用隐藏其他收件人地址 [英] PHP Mail hide other recipient addresses with multiple function calls

查看:254
本文介绍了PHP Mail通过多个函数调用隐藏其他收件人地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 <?php 
$ headers =From:$ _ POST [电子邮件'] \r\\\

$ headers。=Content-type:text / html\r\\\
;
$ array = explode(,,$ _POST ['sendto']);
($ i = 0; $ i< count($ array); ++ $ i){
mail(trim($ array [$ i]),Happy Holidays! body,$ headers);
}
?>

如何解决这个问题,以便收件人只能在到字段中看到他们的电子邮件地址?
谢谢!

解决方案

您要使用的是BCC字段。





代码:

 <?php 

$ _POST ['email'] = str_replace(array(\\\
,\r),'',$ _POST ['email' ]);
$ _POST ['sendto'] = str_replace(array(\\\
,\r),'',$ _POST ['sendto']);

$ headers =From:。 $ _POST ['email']。 \\\\

。 Content-Type:text / html\r\\\

。 BCC:。 $ _POST ['sendto']。 \r\\\
;
mail($ _ POST ['email'],'Happy Holidays!',$ body,$ headers);

?>

发送电子邮件给发件人,但BCC收件人。此外,我从BCC和FROM字段中删除了\r和\\\
的字符,否则将允许邮件头注入攻击。确保对$ body执行相同操作。


I have a PHP script which sends an e-card to multiple recipients in function calls (takes an array of comma-separated email addresses and mail()s to each one individually). However, when looking at the received email, each client can see the other addresses that the email was sent to, making me believe they are all being sent in one email, despite the separate mail() calls. Here is my current code:

<?php
$headers  = "From: ".$_POST['email']."\r\n"; 
$headers .= "Content-type: text/html\r\n";
$array=explode(",", $_POST['sendto']);
for ($i = 0; $i < count($array); ++$i) {
    mail(trim($array[$i]), "Happy Holidays!", $body, $headers);
}
?>

How do I fix this so that the recipient can only see their email address in the "to" field? Thanks!

解决方案

What you want to use is the BCC field.

Code:

<?php

$_POST['email'] = str_replace(array("\n", "\r"), '', $_POST['email']);
$_POST['sendto'] = str_replace(array("\n", "\r"), '', $_POST['sendto']);

$headers = "From: " . $_POST['email'] . "\r\n"
         . "Content-Type: text/html\r\n"
         . "BCC: " . $_POST['sendto'] . "\r\n";
mail($_POST['email'], 'Happy Holidays!', $body, $headers);

?>

Send the email to the sender, but BCC the recipients. Also I removed \r and \n chars from the BCC and FROM field otherwise will allow mail header injection attack. Make sure to do the same to $body.

这篇关于PHP Mail通过多个函数调用隐藏其他收件人地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆