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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesmoore
    New Member
    • Jan 2011
    • 47

    #1

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

    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
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    You're not providing any information about the code whatsoever. It's impossible to know how to advise you.

    Comment

    • jamesmoore
      New Member
      • Jan 2011
      • 47

      #3
      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="content-type"
      content="text/html; charset=iso-8859-1" />
      <title>Emailing Form Data</title>
      <link rel="stylesheet" type="text/css" href="mainform.css" />
      </head>
      <body>
      <div id="form">
      <h2>Ordering your new bed</h2>
      <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>
      
      <form method="post" action="emailform.php">
      <p class="legend">Personal information</p>
      <fieldset id="personal">
      <label>Name:</label><input type="text" name="name" size="30" /> <br />
      <label>Email:</label><input type="text" name="email" size="30" /> <br/>
      <label>Address:</label><input type="text" name="address" size="30" /> <br />
      <label>Town/City:</label><input type="text" name="city" size="30" /> <br />
      <label>State:</label><input type="text" name="state" size="2" maxlength="2" /><br /> 
      <label>Zipcode:</label><input type="text" name="zip" size="5" maxlength="5" /> <br />
      <label>Customer ID:</label><input type="password" name="code" size="8" />
      </fieldset>
      
      <p class="legend">Choices</p>
      <fieldset id="choices">
      <p id="woodtype"><label>Type of wood:</label><select name="woodtype">
      <option value="Mahogany">Mahogany</option>
      <option value="Maplewood">Maplewood</option>
      <option value="Pine">Pine</option>
      <option value="Cherry">Cherry</option>
      </select></p>
      
      <p id="size"><label>Size:</label><input type="radio" name="size" value="K" />King 
      <input type="radio" name="size" value="Q" />Queen <br />
      <input type="radio" name="size" value="T" />Twin 
      <input type="radio" name="size" value="S" />Single</p>
      
      <p id="extras"><label>Extras:</label>
      <input type="checkbox" name="extras[]" value="foot" />Footboard 
      <input type="checkbox" name="extras[]" value="drawers" checked="checked" />Drawers  <br />
      <input type="checkbox" name="extras[]" value="casters" />Casters <input type="checkbox" name="extras[]" value="nosqueak" />Squeak proofing <br />
      </p>
      </fieldset>
      
      <p class="legend">Suggestions</p>
      <fieldset id="suggestions">
      <textarea
      name="comments" rows="3" cols="40">Please share any comments you have here</textarea>
      </fieldset>
      
      <p id="buttons"><input type="submit" value="Order Bed"  />
      <input type="reset" value="Start Over" /></p>
      
      </form>
      </div>
      </body>
      </html>
      AND THE PHP CODE
      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      	<title>Emailing Form Data</title>
      <style type="text/css">
      code {color:#F00C4D;font-weight:bold;font-size:1.2em}
      i {color: #6D0CF0}
      th, td {padding:.1em;border:1px solid blue;text-align:left}
      </style>
      </head>
      <body>
      
      
      <?php
      //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).
      
      if (empty($_POST)) {
      	print "<p>No data was submitted.</p>";
      	print "</body></html>";
      	exit();
      }
      
      //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!
      function clear_user_input($value) {
      	if (get_magic_quotes_gpc()) $value=stripslashes($value);
      	$value= str_replace( "\n", '', trim($value));
      	$value= str_replace( "\r", '', $value);
      	return $value;
      	}
      
      
      if ($_POST['comments'] == 'Please share any comments you have here') $_POST['comments'] = '';	
      
      //Create body of message by cleaning each field and then appending each name and value to it
      
      $body ="Here is the data that was submitted:\n";
      
      foreach ($_POST as $key => $value) {
      	$key = clear_user_input($key);
      	$value = clear_user_input($value);
      	if ($key=='extras') {
      		
      	if (is_array($_POST['extras']) ){
      		$body .= "$key: ";
      		$counter =1;
      		foreach ($_POST['extras'] as $value) {
      				//Add comma and space until last element
      				if (sizeof($_POST['extras']) == $counter) {
      					$body .= "$value\n";
      					break;}
      				else {
      					$body .= "$value, ";
      					$counter += 1;
      					}
      				}
      		} else {
      		$body .= "$key: $value\n";
      		}
      	} else {
      
      	$body .= "$key: $value\n";
      	}
      }
      
      extract($_POST);
      //removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
      $email = clear_user_input($email);
      $name = clear_user_input($name);
      
      //Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
      $from='From: '. $email . "(" . $name . ")" . "\r\n" . 'Bcc: yourmail@yourdomain.com' . "\r\n";
      
      
      //Creates intelligible subject line that also shows me where it came from
      $subject = 'Bed Order from Web Site';
      
      //Sends mail to me, with elements created above
      mail ('youremail@yourdomain.com', $subject, $body, $from);
      
      
      ?>
      
      <p>Thanks for your order! We'll send your bed right away.</p>
      
      
      </body>
      </html>
      Thanks. James

      Comment

      Working...