webchambers Posted March 26, 2019 Share Posted March 26, 2019 how do i alter this code so that the recipients don't see other email addresses ? <?php if(count($_POST)) { # This part strips out nasty code that a malicious # person may try to inject into the form foreach(array('email1','email2','email3','youremail','yourname') as $key) $_POST[$key] = strip_tags($_POST[$key]); if(!is_secure($_POST)) { die("Hackers begone");} # This part submits a notification to you when # the form is submitted // Email address for copies to be sent to - change to suit $emailto = "my email"; // Notification email subject text for copies $esubject = "Recommendation form submission"; // Email body text for notifications $emailtext = " $_POST[yourname] has used your recommendation form using an email address of $_POST[youremail] The people the recommendation has been submitted to are: $_POST[email1] $_POST[email2] $_POST[email3] The page recommended: $_POST[refurl] "; # This function sends the email to you @mail("$emailto", $esubject, $emailtext, "From: $_POST[youremail]"); # This part is the function for sending to recipients // Page to display after successful submission // Change the thankyou.htm to suit $thankyoupage = "thankyou.html"; // Subject line for the recommendation - change to suit $tsubject = "A web page recommendation from $_POST[yourname]"; // Change the text below for the email // Be careful not to change anyt "$_POST[value]" bits $ttext = " Hi, $_POST[yourname], whose email address is $_POST[youremail] thought you may be interested in this web page. $_POST[refurl] $_POST[yourname] has used our Tell-a-Friend form to send you this note. We look forward to your visit! "; # This sends the note to the addresses submitted @mail($_POST[email1],$_POST[email2],$_POST[email3]", $tsubject, $ttext, "FROM: $_POST[youremail]"); # After submission, the thank you page header("Location: $thankyoupage"); exit; } # Nothing further can be changed. Leave the below as is function is_secure($ar) { $reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i"; if(!is_array($ar)) { return preg_match($reg,$ar);} $incoming = array_values_recursive($ar); foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false; return true; } function array_values_recursive($array) { $arrayValues = array(); foreach ($array as $key=>$value) { if (is_scalar($value) || is_resource($value)) { $arrayValues[] = $value; $arrayValues[] = $key; } elseif (is_array($value)) { $arrayValues[] = $key; $arrayValues = array_merge($arrayValues, array_values_recursive($value)); } } return $arrayValues; } ?> Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 26, 2019 Share Posted March 26, 2019 Instead of using the TO field, put all the recipients in the BCC field. I suggest you use PHPMailer as it is much easier and gives you much more control. Quote Link to comment Share on other sites More sharing options...
webchambers Posted March 26, 2019 Author Share Posted March 26, 2019 10 minutes ago, gw1500se said: Instead of using the TO field, put all the recipients in the BCC field. I suggest you use PHPMailer as it is much easier and gives you much more control. sorry i got this script off the net do you mean $emailto no idea of coding ! Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 26, 2019 Share Posted March 26, 2019 (edited) Sort of. Make the first parameter (which is the TO field) an empty string (""). Then use "extra headers" and add the BCC field with all the recipients. See the documentation. As I said if you use PHPMailer it will be much easier. Edited March 26, 2019 by gw1500se Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.