Forum Moderators: coopster
Here is my following PHP code:
<?php
$emails = array("info@example.com", "webmaster@example.com", "sales@example.com", "suggestions@example.com", "forum@example.com", "newsletter@example.com", "editor@example.com", "news@example.com", "christian@example.com");
if(in_array($_POST['recipient'], $emails)){ //in_array() is case sensitive
//mail function goes here
if ($_POST["image"] == "26mush3") {
if ($_SERVER['REQUEST_METHOD']=="POST"){
// In testing, if you get an Bad referer error
// comment out or remove the next three lines
if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ¦¦
!strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
die("Bad referer");
$msg="Values submitted by the user:\n";
foreach($_POST as $key => $val){
if (is_array($val)){
$msg.="Item: $key\n";
foreach($val as $v){
$v = stripslashes($v);
$msg.=" $v\n";
}
} else {
$val = stripslashes($val);
$msg.="$key: $val\n";
}
}
$recipient=($_POST["recipient"]);
$subject="example.com Contact Form";
error_reporting(0);
if (mail($recipient, $subject, $msg, "", "-f christian@example.com")){
echo "<h1 style=text-align:center>Thank You ".$_POST["full_name"]."</h1>";
echo "<p style=text-align:center>Message successfully sent! <a href=http://www.example.com>Click here</a> to return to the example.com home page.</p><br>\n";
echo nl2br($input);
} else
echo "An error occurred and the message could not be sent.";
} else
echo "Bad request method";
} else {
echo "<center>You did not enter the proper image verification code. Please hit your back button and try again.</center>";
}
} else {
echo "<center>Bad request method.</center>";
}
?>
Thanks!
[edited by: eelixduppy at 7:53 pm (utc) on Sep. 20, 2007]
[edit reason] please use example.com [/edit]
Just make sure that you check for an image file before you allow the upload to take place. You wouldn't want any malicious code to be uploaded to your server.