Jump to content

php mail function


webchambers

Recommended Posts

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;
}

?>

Link to comment
Share on other sites

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 !

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.