473,486 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

when i submit my email form the php is not executed but an open/save prompt comes up?

47 New Member
Hi,

I have tried to test my php for ages now but when i test a form and click submit instead of the form data being sent to my email a prompt comes up asing me to open/save the php folder. What do I do?

Thanks,

James
Mar 28 '11 #1
2 3042
dgreenhouse
250 Recognized Expert Contributor
You're not providing any information about the code whatsoever. It's impossible to know how to advise you.
Mar 28 '11 #2
jamesmoore
47 New Member
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="content-type"
  6. content="text/html; charset=iso-8859-1" />
  7. <title>Emailing Form Data</title>
  8. <link rel="stylesheet" type="text/css" href="mainform.css" />
  9. </head>
  10. <body>
  11. <div id="form">
  12. <h2>Ordering your new bed</h2>
  13. <p>Please fill out the form below to order your new bed. If you have any questions, don't hesitate to <a href="contactform.html">contact us</a>.</p>
  14.  
  15. <form method="post" action="emailform.php">
  16. <p class="legend">Personal information</p>
  17. <fieldset id="personal">
  18. <label>Name:</label><input type="text" name="name" size="30" /> <br />
  19. <label>Email:</label><input type="text" name="email" size="30" /> <br/>
  20. <label>Address:</label><input type="text" name="address" size="30" /> <br />
  21. <label>Town/City:</label><input type="text" name="city" size="30" /> <br />
  22. <label>State:</label><input type="text" name="state" size="2" maxlength="2" /><br /> 
  23. <label>Zipcode:</label><input type="text" name="zip" size="5" maxlength="5" /> <br />
  24. <label>Customer ID:</label><input type="password" name="code" size="8" />
  25. </fieldset>
  26.  
  27. <p class="legend">Choices</p>
  28. <fieldset id="choices">
  29. <p id="woodtype"><label>Type of wood:</label><select name="woodtype">
  30. <option value="Mahogany">Mahogany</option>
  31. <option value="Maplewood">Maplewood</option>
  32. <option value="Pine">Pine</option>
  33. <option value="Cherry">Cherry</option>
  34. </select></p>
  35.  
  36. <p id="size"><label>Size:</label><input type="radio" name="size" value="K" />King 
  37. <input type="radio" name="size" value="Q" />Queen <br />
  38. <input type="radio" name="size" value="T" />Twin 
  39. <input type="radio" name="size" value="S" />Single</p>
  40.  
  41. <p id="extras"><label>Extras:</label>
  42. <input type="checkbox" name="extras[]" value="foot" />Footboard 
  43. <input type="checkbox" name="extras[]" value="drawers" checked="checked" />Drawers  <br />
  44. <input type="checkbox" name="extras[]" value="casters" />Casters <input type="checkbox" name="extras[]" value="nosqueak" />Squeak proofing <br />
  45. </p>
  46. </fieldset>
  47.  
  48. <p class="legend">Suggestions</p>
  49. <fieldset id="suggestions">
  50. <textarea
  51. name="comments" rows="3" cols="40">Please share any comments you have here</textarea>
  52. </fieldset>
  53.  
  54. <p id="buttons"><input type="submit" value="Order Bed"  />
  55. <input type="reset" value="Start Over" /></p>
  56.  
  57. </form>
  58. </div>
  59. </body>
  60. </html>
  61.  
AND THE PHP CODE
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <title>Emailing Form Data</title>
  6. <style type="text/css">
  7. code {color:#F00C4D;font-weight:bold;font-size:1.2em}
  8. i {color: #6D0CF0}
  9. th, td {padding:.1em;border:1px solid blue;text-align:left}
  10. </style>
  11. </head>
  12. <body>
  13.  
  14.  
  15. <?php
  16. //This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).
  17.  
  18. if (empty($_POST)) {
  19.     print "<p>No data was submitted.</p>";
  20.     print "</body></html>";
  21.     exit();
  22. }
  23.  
  24. //Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
  25. function clear_user_input($value) {
  26.     if (get_magic_quotes_gpc()) $value=stripslashes($value);
  27.     $value= str_replace( "\n", '', trim($value));
  28.     $value= str_replace( "\r", '', $value);
  29.     return $value;
  30.     }
  31.  
  32.  
  33. if ($_POST['comments'] == 'Please share any comments you have here') $_POST['comments'] = '';    
  34.  
  35. //Create body of message by cleaning each field and then appending each name and value to it
  36.  
  37. $body ="Here is the data that was submitted:\n";
  38.  
  39. foreach ($_POST as $key => $value) {
  40.     $key = clear_user_input($key);
  41.     $value = clear_user_input($value);
  42.     if ($key=='extras') {
  43.  
  44.     if (is_array($_POST['extras']) ){
  45.         $body .= "$key: ";
  46.         $counter =1;
  47.         foreach ($_POST['extras'] as $value) {
  48.                 //Add comma and space until last element
  49.                 if (sizeof($_POST['extras']) == $counter) {
  50.                     $body .= "$value\n";
  51.                     break;}
  52.                 else {
  53.                     $body .= "$value, ";
  54.                     $counter += 1;
  55.                     }
  56.                 }
  57.         } else {
  58.         $body .= "$key: $value\n";
  59.         }
  60.     } else {
  61.  
  62.     $body .= "$key: $value\n";
  63.     }
  64. }
  65.  
  66. extract($_POST);
  67. //removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
  68. $email = clear_user_input($email);
  69. $name = clear_user_input($name);
  70.  
  71. //Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
  72. $from='From: '. $email . "(" . $name . ")" . "\r\n" . 'Bcc: yourmail@yourdomain.com' . "\r\n";
  73.  
  74.  
  75. //Creates intelligible subject line that also shows me where it came from
  76. $subject = 'Bed Order from Web Site';
  77.  
  78. //Sends mail to me, with elements created above
  79. mail ('youremail@yourdomain.com', $subject, $body, $from);
  80.  
  81.  
  82. ?>
  83.  
  84. <p>Thanks for your order! We'll send your bed right away.</p>
  85.  
  86.  
  87. </body>
  88. </html>
  89.  
Thanks. James
Mar 28 '11 #3

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

Similar topics

1
3226
by: Joe | last post by:
In the following code, page1.asp is inside the frame of main.html. When the user click submit button in page1.asp, it will submit the for and open a new window called page2.asp. When the user...
4
2795
by: Timothy Madden | last post by:
Hello all I have a little problem and I hope it is simple. I have a form on my page and I have to open a pop-up window with the page serverd after the form submit. I know I can compose the URL...
3
1462
by: besbello | last post by:
Hi all, I want to submit a form when the user closes the browser, to keep a count of the number of users accesing my application at each moment. To do this, I use the onbeforeunload() event, that...
7
25821
by: palgrave | last post by:
Hi, How do you create an html link from a web page to a read-only excel spreadsheet without the browser asking if the user wants to open it or save it?
1
2635
by: jongyoo | last post by:
Hey guys, I'm having some trouble scripting someway where I can submit a form and open up a new window at the same time, so I would have two windows open. Thanks
0
1748
by: Server Control | last post by:
Hi, I am exporting my datagrid to Excel using the standard Export to Excel Method using : dg.RenderControl(). and Page.Response.AddHeader("Content-Disposition", "attachment;filename=" +...
3
5545
by: Sheau Wei | last post by:
i would like to create a prompt up messsage in when submit a form, how to make it?
6
6882
by: Harshpandya | last post by:
Hi all, I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different...
11
5263
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
0
7099
marktang
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,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
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...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
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...
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
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...

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.