Hello,
I was given this coding a long time ago from this website by a user and I have used it for years on one of my website. I have built another website and used the same coding. However, when I pull up the page that has the contact form on it, it says "Call to undefined function: html_entity_decode() on line 218. So, I can't figure out why it won't work on the new website. Line 218 has
$userName = html_entity_decode($userName);
But, here's the first half of the coding for the script:
<?php
//----- Start Config -----\\
//enter the path to sendmail
$mail_path = "/usr/sbin/sendmail";
//Recipient should be selected from a list, true or false
$listofrecipients = "true";
//sub variable (only edit if above value is set to false)
//enter the email address you wish emails to be sent to
$mail_to = "you@yourdomain.com";
//sub variable (only edit if above value is set to true)
//define list of recipients the user can chose from. Name & Email address should be seperated by ><
$recipientslist = array("Name, Title >< [email]you@yourdomain.com[/email]", "Name, Title >< [email]you@yourdomain.com[/email]");
//Subject should be selected from a list, true or false
$listofsubjects = "false";
//sub variable (only edit if above value is set to true)
//define list of subjects the user can chose from
$subjects = array("Subject 1", "Subject 2", "Subject 3");
//use security code feature, true or false
$usesecuritycode = "true";
//use time limit feature, true or false
$usetimelimit = "false";
//sub variable (only edit if above value is set to true)
//set time delay if using time limit feature
$delay = "60";
//redirect to another page after successful submission, true or false
$redirectonsuccess = "true";
//sub variable (only edit if above value is set to true)
//set address of page to redirect to after successful submission, can be relative
$redirecturl = "http://www.yourdomain.com/ok.htm";
//allow user to get a copy of the message sent to them, true or false
$copyme = "false";
//store submissions in a database, true or false
$store = "false";
//sub variables (only edit if above value is set to true
//MySQL Host
$host = "localhost";
//MySQL User
$user = "user";
//MySQL Pass
$pass = "pass";
//MySQL Database Name
$dbname = "database";
//Table Name
$tablename = "ContactFormLog";
//Date Format, see [url]http://www.php.net/date[/url]
$dateformat = "d/m/Y H:i:s";
//user has to preview before can submit, true or false
$preview = "false";
//remember user's name and e-mail, true or false
$rememberdetails = "false";
//sub variables (only edit if above value is set to true
//Days to remember details for
$rememberdays = "7";
//----- End Config -----\\
//----- Start Set PHP Variables -----\\
ini_set("sendmail_path", $mail_path);
ini_set("magic_quotes_gpc", 1);
//----- End Set PHP Variables -----\\
//----- Start Functions -----\\
//function to check email format
function check_email($str)
{
if(ereg("^.+@.+\\..+$", $str))
return 1;
else
return 0;
}
//function to get submitted values
function get_values($slashes,$decode)
{
global $userName;
global $userEmail;
global $userSubject;
global $userMessage;
global $userCopyMe;
global $userEmailTo;
global $rememberdetails;
$userName = htmlentities(strip_tags($_POST['userName']));
$userEmail = htmlentities(strip_tags($_POST['userEmail']));
$userSubject = htmlentities(strip_tags($_POST['userSubject']));
$userMessage = htmlentities(strip_tags($_POST['userMessage']));
$userCopyMe = htmlentities(strip_tags($_POST['userCopyMe']));
$userEmailTo = htmlentities(strip_tags($_POST['userEmailTo']));
if ($slashes == "1") {
$userName = stripslashes($userName);
$userEmail = stripslashes($userEmail);
$userSubject = stripslashes($userSubject);
$userMessage = stripslashes($userMessage);
$userCopyMe = stripslashes($userCopyMe);
$userEmailTo = stripslashes($userEmailTo);
}
if ($decode == "1") {
$userName = html_entity_decode($userName);
$userEmail = html_entity_decode($userEmail);
$userSubject = html_entity_decode($userSubject);
$userMessage = html_entity_decode($userMessage);
$userCopyMe = html_entity_decode($userCopyMe);
$userEmailTo = html_entity_decode($userEmailTo);
}
}
//function to clear submitted values
function clear_values()
{
global $userName;
global $userEmail;
global $userSubject;
global $userMessage;
global $userCopyMe;
global $userEmailTo;
global $rememberdetails;
if ($rememberdetails != "true") {
$userName = "";
$userEmail = "";
}
$userSubject = "";
$userMessage = "";
$userCopyMe = "";
$userEmailTo = "";
}
//function to display message
function display_messages()
{
global $message;
global $messagenoterror;
$y = "0";
if (!empty($message) && $messagenoterror != "1") {
echo "***The following errors were encountered when trying to process your comments:<br><br>";
}
while ($y < 10) {
if (!empty($message[$y])) {
if ($messagenoterror != "1") {
echo " - ";
}
echo $message[$y]."<br />";
}
$y++;
}
}
//----- End Functions -----\\
//----- Start Set Variables -----\\
$mail_subject = $_POST['userSubject'];
$submittime = $_SESSION['submittime'];
$currenttime = time();
$allowedtime = $currenttime - $delay;
$timeleft = $submittime - $allowedtime;
$p = "0";
get_values(1,1);
$EmailContent = "Name:\n".$userName."\n\n"."Email:\n".$userEmail."\n\n"."Subject:\n".$userSubject."\n\n"."Message:\n".$userMessage."\n\n"."User Agent:\n".$_SERVER["HTTP_USER_AGENT"]."\n\n"."User IP:\n".$_SERVER["REMOTE_ADDR"];
//----- End Set Variables -----\\
//check if form submitted
if ($_POST){
//----- Start Error Checking -----\\
//check to see if fields already been checked
if ($_POST['previewdone'] != "1") {
//check if all fields filled in
if (!$_POST['userName'] || !$_POST['userEmail'] || !$_POST['userSubject'] || !$_POST['userMessage']){
$message[$p] = "All fields are required. One or more fields were not filled in.";
$p++;
get_values(1,0);
$notcomplete = "1";
}
//check if email is in valid format
if(check_email($_POST['userEmail']) == "0" && $_POST['userEmail']){
$message[$p] = "Your e-mail address is invalid.";
$p++;
get_values(1,0);
}
//check if security code is correct
if($_POST['userSecurityCode'] != base64_decode($_POST['SecurityCode']) && $usesecuritycode == "true" && $notcomplete != "1"){
$message[$p] = "Wrong security code";
$p++;
get_values(1,0);
}
//check that x seconds has passed
if($submittime > $allowedtime && $usetimelimit == "true"){
$message[$p] = "You are trying to send messages too often, please try again after ".$timeleft." seconds";
$p++;
get_values(1,0);
}
}
//----- End Error Checking -----\\
//----- Start Set Cookies ------\\
if ($rememberdetails == "true") {
$cookietime = time()+60*60*24*$rememberdays;
//set cookie to remember userid for x days
setcookie("userName", $_POST['userName'], $cookietime, "/");
//set cookie to remember password for x days
setcookie("userEmail", $_POST['userEmail'], $cookietime, "/");
}
//----- End Set Cookies ------\\
//----- Start Final Check & Process Form ------\\
if ($preview == "true" && $_POST['previewdone'] == "1") {
$continue = "1";
} elseif ($preview == "true" && $_POST['previewdone'] != "1") {
$continue = "0";
} else {
$continue = "1";
}
//check to see whether there are any errors, if no then continue
if (empty($message) && $continue == "1" && empty($_POST['edit'])){
//check to see whether the user can pick the recipitent, if yes get recepitent chosen
if ($listofrecipients == "true") {
$explodedresult = explode(" >< ", $recipientslist[$_POST['userEmailTo']]);
$mail_to = $explodedresult[1];
}
//Check to see if mail sent correctly
get_values(1,0);
if(mail($mail_to,$mail_subject,$EmailContent,"From:".$userName." <".$userEmail.">")){
//check to see if user wants a copy of the message, if yes send them one
if ($_POST['userCopyMe'] == "1"){
mail($_POST['userEmail'],"Copy of sent message: ".$mail_subject,$EmailContent,"From:".$userName." <".$userEmail.">");
}
//check to see if user wants to store submissions
if ($store == "true") {
//connect to db
$connect = @mysql_connect($host,$user,$pass);
//select db
$selectdb = @mysql_select_db($dbname);
//get variables
get_values(1,1);
$userAgent = $_SERVER["HTTP_USER_AGENT"];
$userIP = $_SERVER["REMOTE_ADDR"];
$userTime = date($dateformat);
//insert data
$sql = "INSERT INTO `$tablename` (`ID`, `userName`, `userEmail`, `userSubject`, `userMessage`, `userCopyMe`, `userEmailTo`, `userAgent`, `userIP`, `userTime`) VALUES ('', '$userName', '$userEmail', '$userSubject', '$userMessage', '$userCopyMe', '$userEmailTo', '$userAgent', '$userIP', '$userTime')";
$result = @mysql_query($sql);
}
//tell user message sent successfully
$message[0] = "Thank you, your message has been sent.";
$messagenoterror = "1";
//clear form values
clear_values();
//store submit time for use with time limit feature
$_SESSION['submittime'] = time();
//check to see if user should be redirected
if ($redirectonsuccess == "true") {
?>
<script type="text/javascript">
<!--
window.location.href = "<?php echo $redirecturl; ?>";
-->
</script>
<?php
}