0

Hello. I have a form page that has been created with the fields: Name, Email, Phone (day), Phone (Eve), Address, and Comments. The form will need to be sent to an email address upon clicking the submit button. I have read some previous posts and tried using some of the code suggested with the code below being one that worked for another user. When I go to the testing server to test the form I get an htdocs/missing.htm page instead of the form being submitted or giving a form not submitted error message. Could there be a problem with the permissions of the file, or am I missing something with the code? Thanks.
Here is the code:

<!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">
<head>
<title> - City Hall Directory</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<form id="form1" method="post" action="<?php echo $me;?>">
  <p><span class="style6">Name
      </span><br />
      <input name="textfield" type="text" class="form" />
  </p>
  <p><span class="style6">Email
    </span><br />
    <input name="textfield2" type="text" class="form" />
  </p>
  <p><span class="style6">Phone (day)
    </span><br />
    <input name="textfield3" type="text" class="form" />
  </p>
  <p><span class="style6">Phone (eve)
    </span><br />
    <input name="textfield4" type="text" class="form" />
  </p>
  <p><span class="style6">Address
    </span><br />
    <input name="textfield5" type="text" class="form" />
  </p>
  <p><span class="style6">Comments </span><br />
    <textarea name="textfield6" cols="50" rows="10" class="form"></textarea>
  </p>
  <p>&nbsp;</p>
  <p>
    <input name="Submit" type="submit" class="form" value="Send" />
  </p>
</form>
<?
$formgood = true;
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone day = $_POST['Phone (day)'];
$phone eve = $_POST['Phone (eve)'];
$addfress = $_POST['Address'];
$comments = $_POST['comments'];
$to = "email@domainname.com"; //Please change this to your e-mail address
$message = "$name has submitted a contact form. \n\n $comments \n\n You can reply to $email";
//check to make sure all form elements were filled in
if ($name == "") {
    echo 'You must provide your name to contact us. Please click the back, and try again';
 $formgood = false;
}
if ($email == "") {
    echo 'We require an e-mail address in order for us to respond. Please go back and try again.';
 $formgood = false;
}
if ($comments == "") {
    echo 'You must provide comments in order to submit this form. Please click back, and try again.';
 $formgood = false;
}
if ($formgood) {
    if(mail($to, "A contact us form has been submitted by $name", $message, "From: $email\n")) {
   echo 'Thank you for submitting this form. We will review your comments and contact you shortly. <br>';
}
else
{
echo "An error has occured. Please contact the webmaster.";
}
 }
else {
  
echo "<br> Please review the comments above and try again.";
      
}
?>
<p><br />
    </p>
    <p> </p>
    <p>  
</div>
<br />
<p>&nbsp;</p>
</div>
</div>

<!-- end #primaryContent -->
</div> 
</script>
</body>
</html>
3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by macneato
0

Where you have this <?php echo $me;?> I have the actual php file name listed there. Might want to try that

Hello. I have a form page that has been created with the fields: Name, Email, Phone (day), Phone (Eve), Address, and Comments. The form will need to be sent to an email address upon clicking the submit button. I have read some previous posts and tried using some of the code suggested with the code below being one that worked for another user. When I go to the testing server to test the form I get an htdocs/missing.htm page instead of the form being submitted or giving a form not submitted error message. Could there be a problem with the permissions of the file, or am I missing something with the code? Thanks.
Here is the code:

<!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">
<head>
<title> - City Hall Directory</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<form id="form1" method="post" action="<?php echo $me;?>">

0

So I need to create a seperate php file in order to accomplish this?

0

Hi dbow1,

Create the following php document and save it as mail.php:

<?php

$visitor = $_POST['name']; 
$visitormail = $_POST['email']; 
$address = $_POST[['address'];
$tele = $_POST['tele'];
$teld = $_POST['teld'];
$notes = $_POST['comments'];


// form validation

if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if ($visitor == "") {
echo 'You must provide your name to contact us. Please click the back, and try again';
$formgood = false;
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
if ($comments == "") {
echo 'You must provide comments in order to submit this form. Please click back, and try again.';
}
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! "); 
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ; 
$subject = $notes; 

$notes = stripcslashes($notes); 

$message = " $todayis [EST] \n
Message: $notes \n 
From: $visitor ($visitormail)\n
Address: $address \n
Telephone (Day): $teld \n
Telephone (Evening): $tel \n
";

$from = "From: $visitormail\r\n";

// Change the email address to the one you use.

mail("you@email.com", $subject, $message, $from);

?>

<!-- Below is the confirmation message the user will see -->

<p align="center">
Date: <?php echo $todayis ?> 
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
<br />
Telephone Numbers: <?php echo $teld ?>  ( <?php echo $tele ?> ) 
<br />
Address: <?php echo $address ?>
<br />
Message: <?php echo $notes ?>
<br /> 
Message:<br /> 
<?php $notesout = str_replace("\r", "<br/>", $notes); 
echo $notesout; ?> 
<br />
<?php echo $ip ?> 

<br /><br />
<a href="index.html"> Home </a></p>

Then place it in the same folder as your contact us page (contact_us.html)

To make things a little easier, I have created the form for you as well, place this code, where you would like the contact us form to appear:

<div id="container">
<form method="post" action="mail.php">
	<div id="row">
		<div id="col"> Name: </div>
		<div id="col"> <input name="name" type="text" id="name" /> </div>
	</div>
	<div id="row">
		<div id="col"> Email: </div>
		<div id="col"> <input name="email" type="text" id="email" /> </div>
	</div>
	<div id="row">
		<div id="col"> Phone (day): </div>
		<div id="col"> <input name="teld" type="text" id="tel_day" /> </div>
	</div>
	<div id="row">
		<div id="col"> Phone (evening): </div>
		<div id="col"> <input name="tele" type="text" id="tel_evening" /> </div>
	</div>
	<div id="row">
		<div id="col"> Address: </div>
		<div id="col"> <input name="address" type="text" id="address" /> </div></div>
	<div id="row">
		<div id="col"> Comments: </div>
		<div id="col"><textarea name="comments" cols="50" rows="10"></textarea></div>
	</div>
  <div id="row"><input name="send" type="submit" id="send" value="Send" />
	  <input name="clear" type="reset" id="clear" value="Clear" />
	</div>
</form>
</div>

And Finally, the CSS you need to style the form:

#container {
	width: 768px;
	height: 400px;
	}

#row {
	width:100%;
	margin:2px;
	height:auto;
	float:left;
}

#col{
	width:25%;
	margin:2px;
	float:left;
	height:auto;
}

If you have any problems or need some help. Just ask.

Regards,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.