473,549 Members | 3,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to know where to direct the php form and where to place in html?

I am new to PHP and have been reading tutorials all day. I'm trying to write code so my "contact us" form generates an email and sends when clicking on submit. The form is built - I got it from a template and it has been customized, but the PHP is not there yet. Now, I'm trying to marry the php script I have with the html I have to get it to work.

The problem I'm having is knowing exactly where to place the php script, what to put after action=" " to make it work, and if I put emailto:name@ad dress.com as the href.

I'm using the script from this site:

And trying to marry it with my code here:
to generate an email to info(at)getcrea tivesense.com

Where I may be making the mistake is having a separate .php doc (thinking it works like java)

I've read so much info about it today that now I'm completely confused.

Thank you. Here is the code:

Script for PHP:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  6. <title>Sendemail Script</title>
  7. </head>
  8. <body>
  10. <!-- Reminder: Add the link for the 'next page' (at the bottom) --> 
  11. <!-- Reminder: Change 'YourEmail' to Your real email --> 
  13. <?php
  15. $ip = $_POST['ip']; 
  16. $httpref = $_POST['httpref']; 
  17. $httpagent = $_POST['httpagent']; 
  18. $visitor = $_POST['visitor']; 
  19. $visitormail = $_POST['visitormail']; 
  20. $notes = $_POST['notes'];
  21. $attn = $_POST['attn'];
  24. if (eregi('http:', $notes)) {
  25. die ("Do NOT try that! ! ");
  26. }
  27. if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
  28. {
  29. echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
  30. $badinput = "<h2>Feedback was NOT submitted</h2>\n";
  31. echo $badinput;
  32. die ("Go back! ! ");
  33. }
  35. if(empty($visitor) || empty($visitormail) || empty($notes )) {
  36. echo "<h2>Use Back - fill in all fields</h2>\n";
  37. die ("Use back! ! "); 
  38. }
  40. $todayis = date("l, F j, Y, g:i a") ;
  42. $attn = $attn ; 
  43. $subject = $attn; 
  45. $notes = stripcslashes($notes); 
  47. $message = " $todayis [EST] \n
  48. Attention: $attn \n
  49. Message: $notes \n 
  50. From: $visitor ($visitormail)\n
  51. Additional Info : IP = $ip \n
  52. Browser Info: $httpagent \n
  53. Referral : $httpref \n
  54. ";
  56. $from = "From: $visitormail\r\n";
  59. mail("YourEmail", $subject, $message, $from);
  61. ?>
  63. <p align="center">
  64. Date: <?php echo $todayis ?> 
  65. <br />
  66. Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
  67. <br />
  69. Attention: <?php echo $attn ?>
  70. <br /> 
  71. Message:<br /> 
  72. <?php $notesout = str_replace("\r", "<br/>", $notes); 
  73. echo $notesout; ?> 
  74. <br />
  75. <?php echo $ip ?> 
  77. <br /><br />
  78. <a href="contact.php"> Next Page </a> 
  79. </p> 
  81. </body>
  82. </html>
And following, the code from my page:
Expand|Select|Wrap|Line Numbers
  1. <form id="contacts-form" method=post action="contact.php">
  2.                      <fieldset>
  3.                         <div class="col-1">
  4.                             <label>Enter Your Name:<br /><input type="text" name="name" value=""/></label>
  5.                            <label>Enter Your E-mail:<br /><input type="text" name="email" value=""/></label>
  6.                            <label>Enter Your Company:<br /><input type="text" name="company" value=""/></label>
  7.                         </div>
  8.                         <div class="col-2">
  9.                            Enter Your Message:<br /><textarea name="message" cols="" rows=""></textarea>
  10.                            <INPUT type="submit" value="Send Mail">&nbsp;&nbsp;<INPUT TYPE="RESET" value="Clear It">
  11.                         </div>
  12.                     </fieldset>
  13.                   </form>
  14.                </div>
Do I put the php script in the header, like java? Or, in it's own .php file. I'm unclear on that.

Here's the html from the site where I got the script. Since my form has <label> and is formatted a little differently, I am not sure how to incorporate the php prompts:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Email Form </title>
  5. </head>
  6. <body>
  8. <form method="post" action="sendeail.php">
  10. <!-- DO NOT change ANY of the php sections -->
  11. <?php
  12. $ipi = getenv("REMOTE_ADDR");
  13. $httprefi = getenv ("HTTP_REFERER");
  14. $httpagenti = getenv ("HTTP_USER_AGENT");
  15. ?>
  17. <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
  18. <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
  19. <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
  22. Your Name: <br />
  23. <input type="text" name="visitor" size="35" />
  24. <br />
  25. Your Email:<br />
  26. <input type="text" name="visitormail" size="35" />
  27. <br /> <br />
  28. <br />
  29. Attention:<br />
  30. <select name="attn" size="1">
  31. <option value=" Sales n Billing ">Sales n Billing </option> 
  32. <option value=" General Support ">General Support </option> 
  33. <option value=" Technical Support ">Technical Support </option> 
  34. <option value=" Webmaster ">Webmaster </option> 
  35. </select>
  36. <br /><br />
  37. Mail Message:
  38. <br />
  39. <textarea name="notes" rows="4" cols="40"></textarea>
  40. <br />
  41. <input type="submit" value="Send Mail" />
  42. <br />
  43. </form>
  45. </body>
  46. </html>
Nov 3 '10 #1
1 2025
1,584 Recognized Expert Top Contributor
Hey there Gilda, welcome to bytes.

PHP is flexible and free (unlike java and c) that it confuses beginners.

The html <form> tag's action tells where to send the information to. This can be the same file (or blank) or another place. It doesn't haven have to be PHP. The information is sent using the method set in the form. The two popular ones are "get" and "post". These are just methods of how they're stored in the page header and sent across the internet. GET sends it as part of the URL and POST uses embedded header variables that you can't plainly see. POST is preferred for things like long text fields such as an email message.

To get to your question, You can create a PHP document in this server/site or any other site on the web to process the information (in your case, email it) that you receive from the form.

Once the form is submitted, it is like clicking a link. You can land back on the same page and display a message (like "you're email has been sent" or "Error: message cannot be blank")

In your email you have contact.php as the destination (action) of your form, but it should be sendeail.php if that's the script you want to process your form and send an email. It's NOT included in the header like Java.

Hope that clarified any questions you had,

Nov 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Rudi Cheow | last post by:
Hi folks, I will test this when I get back, but just for now can any of you confirm if the following idea will work... I would like to embed a form into an HTML E-Mail. If I set the POST action to a formmail script on the web, will there be a problem? Also, what happens once the user clicks submit - is there any way to define what...
by: Wanjun Yu | last post by:
In C#, what control or form can display HTML? I know in Visual C++, the CHtmlView is the one, but I can't seem to find the couterpart in C#. Thanks. WJ
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. Using Safari,my first iteration the script works fine ( indicating that there are 33 form variables ). When trying another dropdown select value, the
by: sono | last post by:
Today I read there is a possibility to write direct Fench characters in HTML. Thus instead of having to write : L'&eacute;l&egrave;ve va &agrave; l'&eacute;cole et ceci est &eacute;crit en Fran&ccedil;ais! I should be able to directly write it in French, i.e. : L'élève va à l'école et ceci est écrit en Français! (I just hope...
by: ofiras | last post by:
Hello, I need to check for forms in html on the web, and I found this: http://msdn2.microsoft.com/en-us/library/system.web.httprequest.form(VS.90).aspx But I can't find this property in C#... Am I doing something wrong? Is there something else that dose it? If not, I guess I'll need to make my own method that will do it. Please help, Ofir.
by: anusha.vempati9 | last post by:
Hi All, I am calling a cgi file from a perl module. The cgi file contains the HTML form and some HTML fields(like check boxes). In my logic, I am trying to submit the form and calling the same cgi file again. While doing this, i am not able to retain the values of the HTML fields (check boxes values ) which i set earlier before...
by: reginaldmerritt | last post by:
I'm trying to open a form where the value of a field has a date closest to today but not beyond todays date. I guess i need some sort of MAX function in a where statment maybe???? Any ideas how i could do this. Thanks.
by: Bsorensen | last post by:
I have created a Table to track a Name, a project worked on, the amount completed, and the time the project began and ended. My input Form to update the above fields allows the user to put their input their name, select their project from a drop down, and enter the amount of work done. I would like to know how I can place 2 buttons on this...
by: makeveli | last post by:
I have an HTML form (form #1) which uses a java servlet to save customer data through textfield/checkboxes/drop down field values to a mysql database. On the same page i also have a search facility that will search and show the results of a customer search in a small table on the same page using another servlet. Once the table populates with...
Daniel B
by: Daniel B | last post by:
I have tried creating a subform where all the data from the tables is present, therefore the user will have to enter information for a new record into each field. This did not allow me to enter data for some fields, and i was not able to save it into each table. The data is stored in 7 tables, and I cannot figure out how to create a form that...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.