User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Site Layout and Usability section within the Web Development category of DaniWeb, a massive community of 423,433 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,670 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Site Layout and Usability advertiser: Programming Forums
Views: 1234 | Replies: 3
Reply
Join Date: Jun 2008
Posts: 4
Reputation: dbowe1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbowe1 dbowe1 is offline Offline
Newbie Poster

form page to send an email

  #1  
Jun 3rd, 2008
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:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title> - City Hall Directory</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.  
  7. <form id="form1" method="post" action="<?php echo $me;?>">
  8. <p><span class="style6">Name
  9. </span><br />
  10. <input name="textfield" type="text" class="form" />
  11. </p>
  12. <p><span class="style6">Email
  13. </span><br />
  14. <input name="textfield2" type="text" class="form" />
  15. </p>
  16. <p><span class="style6">Phone (day)
  17. </span><br />
  18. <input name="textfield3" type="text" class="form" />
  19. </p>
  20. <p><span class="style6">Phone (eve)
  21. </span><br />
  22. <input name="textfield4" type="text" class="form" />
  23. </p>
  24. <p><span class="style6">Address
  25. </span><br />
  26. <input name="textfield5" type="text" class="form" />
  27. </p>
  28. <p><span class="style6">Comments </span><br />
  29. <textarea name="textfield6" cols="50" rows="10" class="form"></textarea>
  30. </p>
  31. <p>&nbsp;</p>
  32. <p>
  33. <input name="Submit" type="submit" class="form" value="Send" />
  34. </p>
  35. </form>
  36. <?
  37. $formgood = true;
  38. $name = $_POST['Name'];
  39. $email = $_POST['Email'];
  40. $phone day = $_POST['Phone (day)'];
  41. $phone eve = $_POST['Phone (eve)'];
  42. $addfress = $_POST['Address'];
  43. $comments = $_POST['comments'];
  44. $to = "email@domainname.com"; //Please change this to your e-mail address
  45. $message = "$name has submitted a contact form. \n\n $comments \n\n You can reply to $email";
  46. //check to make sure all form elements were filled in
  47. if ($name == "") {
  48. echo 'You must provide your name to contact us. Please click the back, and try again';
  49. $formgood = false;
  50. }
  51. if ($email == "") {
  52. echo 'We require an e-mail address in order for us to respond. Please go back and try again.';
  53. $formgood = false;
  54. }
  55. if ($comments == "") {
  56. echo 'You must provide comments in order to submit this form. Please click back, and try again.';
  57. $formgood = false;
  58. }
  59. if ($formgood) {
  60. if(mail($to, "A contact us form has been submitted by $name", $message, "From: $email\n")) {
  61. echo 'Thank you for submitting this form. We will review your comments and contact you shortly. <br>';
  62. }
  63. else
  64. {
  65. echo "An error has occured. Please contact the webmaster.";
  66. }
  67. }
  68. else {
  69.  
  70. echo "<br> Please review the comments above and try again.";
  71.  
  72. }
  73. ?>
  74. <p><br />
  75. </p>
  76. <p> </p>
  77. <p>
  78. </div>
  79. <br />
  80. <p>&nbsp;</p>
  81. </div>
  82. </div>
  83.  
  84. <!-- end #primaryContent -->
  85. </div>
  86. </script>
  87. </body>
  88. </html>
Last edited by peter_budo : Jun 4th, 2008 at 2:42 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 1
Reputation: 52designs is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
52designs 52designs is offline Offline
Newbie Poster

Re: form page to send an email

  #2  
Jun 3rd, 2008
Where you have this <?php echo $me;?> I have the actual php file name listed there. Might want to try that

[quote=dbowe1;619921]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;?>">
Reply With Quote  
Join Date: Jun 2008
Posts: 4
Reputation: dbowe1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbowe1 dbowe1 is offline Offline
Newbie Poster

Re: form page to send an email

  #3  
Jun 4th, 2008
So I need to create a seperate php file in order to accomplish this?
Last edited by dbowe1 : Jun 4th, 2008 at 12:45 am.
Reply With Quote  
Join Date: Jun 2007
Posts: 179
Reputation: macneato is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 13
macneato's Avatar
macneato macneato is offline Offline
Junior Poster

Re: form page to send an email

  #4  
Jun 4th, 2008
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,
Last edited by macneato : Jun 4th, 2008 at 3:02 am. Reason: Typos
If this reply solved your problem, please add to my reputation and don't forget to mark this thread as solved.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Site Layout and Usability Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Site Layout and Usability Forum

All times are GMT -4. The time now is 2:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC