Hi All,
I am trying to incorporate a php contact form into my web page. I am new to PHP so easily confused .
I downloaded the Contact Form - Style II code from this site:
http://www.kontaktformular.com/en/download-script-php-contact-form.html.
I renamed the âcontact.phpâ file âcontact_form.phpâ because the document that the form is inserted in is called âcontact.phpâ. I inserted the file âcontact_form.phpâ in the page as an âincludeâ.
I also renamed the âCAPTCHAâ file to âcaptcha_formâ because I currently have a folder called âCAPTCHAâ on my root directory for another form, and it wanted to copy over these files. I didnât think I wanted it to do that so I gave the file folder a new name. This may be tripping me up. I went through and tried to change the file name in the code.
When I go to view my page now, all my includes disappear and I get an error message in the middle of the page where the contact form is to go.
Can view at: http://www.sitesbysarh.com/contact.php
I hope I havenât totally lost you. Any ideas why my contact form wonât appear?
Here is the code from my âcontact_form.php pageâ
<?php
session_start();
#########################################################################
# Kontaktformular.com #
# http://www.kontaktformular.com #
# All rights by Michael Knothe #
#-----------------------------------------------------------------------#
# Info: Michael.Knothe@gmx.de #
# I-Net: http://www.kontaktformular.com #
#########################################################################
// It´s not allowed to remove the copyright notice!
$script_root = substr(__FILE__, 0,
strrpos(__FILE__,
DIRECTORY_SEPARATOR)
).DIRECTORY_SEPARATOR;
require_once $script_root.'upload.php';
$remote = getenv("REMOTE_ADDR");
function encrypt($string, $key) {
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
$sicherheits_eingabe = encrypt($_POST["securitycode"], "8h384ls94");
$sicherheits_eingabe = str_replace("=", "", $sicherheits_eingabe);
@require('config.php');
if ($_POST['delete'])
{
unset($_POST);
}
if ($_POST["mt-mk"]) {
$name = $_POST["name"];
$email = $_POST["email"];
$street = $_POST["street"];
$city = $_POST["city"];
$info = $_POST["info"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$securitycode = $_POST["securitycode"];
$date = date("d.m.Y | H:i");
$ip = $_SERVER['REMOTE_ADDR'];
$UserAgent = $_SERVER["HTTP_USER_AGENT"];
$host = getHostByAddr($remote);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$message = stripslashes($message);
if(!$name) {
$fehler['name'] = "<font color=#cc3333>Please enter your <strong>name</strong>.<br /></font>";
}
if (!preg_match("/^[0-9a-zA-ZĂĂĂ_.-]+@[0-9a-z.-]+\\.[a-z]{2,6}$/", $email)) {
$fehler['email'] = "<font color=#cc3333>Please enter a <strong>e-mail-address</strong>.\
<br /></font>";
}
if(!$street) {
$fehler['street'] = '<font color=#cc3333>Please enter a <strong>street</strong>.<br /></font>';
if(!$city) {
$fehler['city'] = '<font color=#cc3333>Please enter your <strong>city and zipcode</strong>.<br /></font>';
if(!$info) {
$fehler['info'] = '<font color=#cc3333>Please enter who info is for <strong>(self, mother, father, etc.)</strong>.<br /></font>';
if(!$subject) {
$fehler['subject'] = '<font color=#cc3333>Please enter a <strong>subject</strong>.<br /></font>';
}
if(!$message) {
$fehler['message'] = '<font color=#cc3333>Please enter a <strong>message</strong>.<br /></font>';
}
if($sicherheits_eingabe != $_SESSION['captcha_spam']){
unset($_SESSION['captcha_spam']);
$fehler['captcha'] = "<font color=#cc3333>You entered a wrong <strong>code</strong>.<br /></font>";
}
if (!isset($fehler) || count($fehler) == 0) {
$error = false;
$errorMessage = '';
$uploadErrors = array();
$uploadedFiles = array();
$totalUploadSize = 0;
if ($cfg['UPLOAD_ACTIVE'] && in_array($_SERVER['REMOTE_ADDR'], $cfg['BLACKLIST_IP']) === true) {
$error = true;
$fehler['upload'] = '<font color=#990000>You have no authorization to upload files.<br /></font>';
}
if (!$error) {
for ($i=0; $i < $cfg['NUM_ATTACHMENT_FIELDS']; $i++) {
if ($_FILES['f']['error'][$i] == UPLOAD_ERR_NO_FILE) {
continue;
}
$extension = explode('.', $_FILES['f']['name'][$i]);
$extension = strtolower($extension[count($extension)-1]);
$totalUploadSize += $_FILES['f']['size'][$i];
if ($_FILES['f']['error'][$i] != UPLOAD_ERR_OK) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
switch ($_FILES['f']['error'][$i]) {
case UPLOAD_ERR_INI_SIZE :
$uploadErrors[$j]['error'] = 'the file is too big (PHP-Ini directive).';
break;
case UPLOAD_ERR_FORM_SIZE :
$uploadErrors[$j]['error'] = 'the file is too big (MAX_FILE_SIZE in HTML-Formular).';
break;
case UPLOAD_ERR_PARTIAL :
if ($cfg['UPLOAD_ACTIVE']) {
$uploadErrors[$j]['error'] = 'the file has been uploaded partially.';
} else {
$uploadErrors[$j]['error'] = 'the file has been sent partially.';
}
break;
case UPLOAD_ERR_NO_TMP_DIR :
$uploadErrors[$j]['error'] = 'No temporarily folder has been found.';
break;
case UPLOAD_ERR_CANT_WRITE :
$uploadErrors[$j]['error'] = 'error during saving the file.';
break;
case UPLOAD_ERR_EXTENSION :
$uploadErrors[$j]['error'] = 'unknown error due to an extension.';
break;
default :
if ($cfg['UPLOAD_ACTIVE']) {
$uploadErrors[$j]['error'] = 'unknown error on uploading.';
} else {
$uploadErrors[$j]['error'] = 'unknown error on sending the email attachments.';
}
}
$j++;
$error = true;
}
else if ($totalUploadSize > $cfg['MAX_ATTACHMENT_SIZE']*1024) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'maximum upload reached ('.$cfg['MAX_ATTACHMENT_SIZE'].' KB).';
$j++;
$error = true;
}
else if ($_FILES['f']['size'][$i] > $cfg['MAX_FILE_SIZE']*1024) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'The file is too big (max. '.$cfg['MAX_FILE_SIZE'].' KB).';
$j++;
$error = true;
}
else if (!empty($cfg['BLACKLIST_EXT']) && strpos($cfg['BLACKLIST_EXT'], $extension) !== false) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'the file extension is not permitted.';
$j++;
$error = true;
}
else if (preg_match("=^[\\\\:*?<>|/]+$=", $_FILES['f']['name'][$i])) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'invalid symbols in the file name (\\/:*?<>|).';
$j++;
$error = true;
}
else if ($cfg['UPLOAD_ACTIVE'] && file_exists($cfg['UPLOAD_FOLDER'].'/'.$_FILES['f']['name'][$i])) {
$uploadErrors[$j]['name'] = $_FILES['f']['name'][$i];
$uploadErrors[$j]['error'] = 'the file already exist.';
$j++;
$error = true;
}
else {
if ($cfg['UPLOAD_ACTIVE']) {
move_uploaded_file($_FILES['f']['tmp_name'][$i], $cfg['UPLOAD_FOLDER'].'/'.$_FILES['f']['name'][$i]);
}
$uploadedFiles[] = $_FILES['f']['name'][$i];
}
}
}
if ($error) {
$errorMessage = 'following errors occured when sending the contact formular:'."\
";
if (count($uploadErrors) > 0) {
foreach ($uploadErrors as $err) {
$tmp .= '<strong>'.$err['name']."</strong><br/>\
- ".$err['error']."<br/><br/>\
";
}
$tmp = "<br/><br/>\
".$tmp;
}
$errorMessage .= $tmp.'';
$fehler['upload'] = $errorMessage;
}
}
// if no error, an email will be sent
if (!isset($fehler))
{
// header of the email
$recipient = "".$empfaenger."";
$betreff = "".$_POST["subject"]."";
$mailheaders = "From: \\"".stripslashes($_POST["name"])."\\" <".$_POST["email"].">\
";
$mailheaders .= "Reply-To: <".$_POST["email"].">\
";
$mailheaders .= "X-Mailer: PHP/" . phpversion() . "\
";
$msg = "The following has been sent by the contact form:\
" . "-------------------------------------------------------------------------\
\
";
$msg .= "Name: " . $name . "\
";
$msg .= "E-Mail: " . $email . "\
\
";
$msg .= "street: " . $street . "\
";
$msg .= "city: " . $city . "\
";
$msg .= "info: " . $info . "\
";
$msg .= "\
Subject: " . $subject . "\
";
$msg .= "Message:\
" . $_POST['message'] = preg_replace("/\\r\\r|\\r\
|\
\\r|\
\
/","\
",$_POST['message']) . "\
\
";
"-------------------------------------------------------------------------\
\
";
if (count($uploadedFiles) > 0) {
if ($cfg['UPLOAD_ACTIVE']) {
$msg .= 'The following files have been uploaded:'."\
";
foreach ($uploadedFiles as $file) {
$msg .= ' - '.$cfg['DOWNLOAD_URL'].'/'.$cfg['UPLOAD_FOLDER'].'/'.$file."\
";
}
} else {
$msg .= 'The following files have been attached:'."\
";
foreach ($uploadedFiles as $file) {
$msg .= ' - '.$file."\
";
}
}
}
$msg .= "\
\
IP address: " . $ip . "\
";
if (!$cfg['UPLOAD_ACTIVE'] && count($uploadedFiles) > 0) {
$attachments = array();
for ($i = 0; $i < $cfg['NUM_ATTACHMENT_FIELDS']; $i++) {
if ($_FILES['f']['name'][$i] == UPLOAD_ERR_NO_FILE) {
continue;
}
$attachments[] = $_FILES['f']['tmp_name'][$i];
}
$boundary = md5(uniqid(rand(), true));
$mailheaders .= "MIME-Version: 1.0\
";
$mailheaders .= "Content-Transfer-Encoding: 8bit\
";
$mailheaders .= "Content-Type: multipart/mixed;\
\ boundary=\\"".$boundary."\\"\
";
$mailheaders .= "\
--".$boundary."\
";
$mailheaders .= "Content-Type: text/plain;\
\ charset=\\"iso-8859-1\\"\
";
$mailheaders .= "Content-Transfer-Encoding: 8bit\
";
for ($i = 0; $i < count($uploadedFiles); $i++) {
$file = fopen($attachments[$i],"r");
$content = fread($file,filesize($attachments[$i]));
fclose($file);
$encodedfile = chunk_split(base64_encode($content));
$msg .= "\
\
--".$boundary."\
";
$msg .= "Content-Type: application/octet-stream;\
\ name=\\"".$uploadedFiles[$i]."\\"\
";
$msg .= "Content-Transfer-Encoding: base64\
";
$msg .= "Content-Disposition: attachment;\
\ filename=\\"".$uploadedFiles[$i]."\\"\
\
";
$msg .= $encodedfile."\
\
";
}
$msg .= "\
\
--".$boundary."--";
}
$msg = strip_tags ($msg);
$dsubject = "Your request"; // Subject of the message
$dmailheaders = "From: ".$ihrname." <".$recipient.">\
";
$dmailheaders .= "Reply-To: <".$recipient.">\
";
$dmsg = "Thank you very much for your e-mail. We will reply as fast as we can.\
\
";
$dmsg .= "Summary: \
" .
"-------------------------------------------------------------------------\
\
";
$dmsg .= "Name: " . $name . "\
";
$dmsg .= "E-Mail: " . $email . "\
\
";
$dmsg .= "street: " . $street . "\
";
$dmsg .= "city: " . $city . "\
";
$dmsg .= "info: " . $info . "\
";
$dmsg .= "\
Subject: " . $subject . "\
";
$dmsg .= "Message:\
" . str_replace("\\r", "", $message) . "\
\
";
if (count($uploadedFiles) > 0) {
$dmsg .= 'You have assigned the following files:'."\
";
foreach ($uploadedFiles as $file) {
$dmsg .= ' - '.$file."\
";
}
}
$dmsg = strip_tags ($dmsg);
if (mail($recipient,$subject,$msg,$mailheaders)) {
mail($email, $dsubject, $dmsg, $dmailheaders);
echo "<META HTTP-EQUIV=\\"refresh\\" content=\\"0;URL=thankyou.php\\">";
exit;
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-DE" lang="de-DE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="language" content="de"/>
<meta name="description" content="kontaktformular.com"/>
<meta name="revisit" content="After 7 days"/>
<meta name="robots" content="INDEX,FOLLOW"/>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Oaknoll Contact Form</title>
<style type="text/css">
body,td,th{font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;color:#000000;}
body{background-color: #FFFFFF;}
a:link, a:visited, a:active{color:#000000;text-decoration:none;}
a:hover{text-decoration: underline;}
.pflichtfeld {
color: #ff0000;}
.neuercode {
color: #0066FF;}
.copyright {
color: #000000;}
</style>
</head>
<body id="Kontaktformularseite">
<div class="kontaktformular">
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<p><input style="width:0px; height:0px; visibility:hidden;" type="hidden" name="action" value="smail" /></p>
<p><input style="width:0px; height:0px; visibility:hidden;" type="hidden" name="content" value="formular"/></p>
<table style="width:500px">
<tr><td colspan="2"></td></tr>
<tr>
<td style="width:150px"><strong>Your Name: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["name"] != "") { echo $fehler["name"]; } ?><input name="name" type="text" value="<?php echo $_POST[name]; ?>" style="width:260px" maxlength="100" /></td>
</tr>
<tr>
<td style="width:150px"><strong>E-Mail: <span class="pflichtfeld">*</span></strong><br /></td>
<td><?php if ($fehler["email"] != "") { echo $fehler["email"]; } ?><input name="email" type="text" id="email" value="<?php echo $_POST[email]; ?>" style="width:260px" maxlength="100" /></td>
</tr>
<tr>
<td style="width:150px"><strong>Street:</strong></td>
<td><input name="street" type="text" value="<?php echo $_POST[street]; ?>" style="width:260px" maxlength="50" /></td>
</tr>
<tr>
<td style="width:150px"><strong>City and Zip:</strong></td>
<td><input name="city" type="text" value="<?php echo $_POST[city]; ?>" style="width:260px" maxlength="50" /></td>
</tr>
<tr>
<td style="width:150px"><strong>Information is for:<br />
(self, father, mother)
</strong></td>
<td><input name="info" type="text" value="<?php echo $_POST[info]; ?>" style="width:260px" maxlength="50" /></td>
</tr>
<tr>
<td style="width:150px"><strong>Subject: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["subject"] != "") { echo $fehler["subject"]; } ?><input name="subject" type="text" value="<?php echo $_POST[subject]; ?>" style="width:260px" maxlength="50" /></td>
</tr>
<tr>
<td style="width:150px"><strong>Message: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["message"] != "") { echo $fehler["message"]; } ?><textarea style="width:260px" name="message" cols="35" rows="10"><?php echo $_POST[message]; ?></textarea></td>
</tr>
<?php
for ($i=0; $i < $cfg['NUM_ATTACHMENT_FIELDS']; $i++) {
echo '<tr>';
echo '<td style="width:150px"><strong>Attachment:</strong></td>';
echo '<td><input type="file" style="width:268px" name="f[]" /></td>';
echo '</tr>';
}
?>
<tr>
<td style="width:150px"> </td>
<td> </td>
</tr>
<tr>
<td style="width:150px"><strong>Security Code:</strong></td>
<td><img src="captcha_form/captcha.php" alt="Security-Code" title="michatronic-sicherheitscode" id="captcha" /><br />
<a href="javascript:void(0);" onclick="javascript:document.getElementById('captcha').src='captcha_form/captcha.php?'+Math.random();"><span class="neuercode">New Code?</span></a></td>
</tr>
<tr>
<td style="width:150px"><strong>Please enter: <span class="pflichtfeld">*</span></strong></td>
<td><?php if ($fehler["captcha"] != "") { echo $fehler["captcha"]; } ?><input type="text" name="securitycode" maxlength="150" style="width:260px" value="" size="20" /></td>
</tr>
<tr>
<td style="width:150px"> </td>
<td> </td>
</tr>
<tr>
<td style="width:150px"> </td>
<td style="font-size:11px">Advice: Fields with <span class="pflichtfeld">*</span> have to be filled.</td>
</tr>
<tr>
<td style="width:150px"></td>
<td> <input type="submit" name="mt-mk" value="Send" onclick="tescht();"/>
<input type="submit" name="delete" value="Delete" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Thanks,
sarb