Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

php form for web sites

I downloaded  a form to put on my web site , I need help figuring out how to send  the information to me, I  am attaching the file.
thank you
form2.html
0
imagekrazy
Asked:
imagekrazy
2 Solutions
 
nap0leonCommented:
Depends on your hosting provider.

GoDaddy, for example, has a feature that let's you tell them to "send this form to me in an email" and it automatically attaches itself to whatever form (or forms!) on your site you want it to.

They also have sample code that you can use so that you can submit the form that you attached to a page that processes the form's information and sends it to you in an email.  

I could write you up some PHP for how to send an email to yourself, but a lot of the information is going to come from your hosting provider anyway... so  you really should start there.
0
 
wadehultsCommented:
Here you go:

Normally I wouldn't post this much code, but I have this method saved as a snippet in my Dreamweaver snippet files. I just modified mine to match your form fields.

<!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=UTF-8">
<title>Untitled Form</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="calendar.js"></script>

<?php
//initialize form variables
$element_2_1 = $element_2_2 = $element_2_2 = $element_5 = $element_1 = $element_3_1 = $element_3_2 = $element_3_3 = $element_4 = $form_id = $saveForm = "";
$emailErr = "";	
	//check page for load or submit
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		//verify correct form id has been submitted to reduce Cross-Site Scripting
		if (isset($_POST["form_id"]))	{
			if ($_POST["form_id"] === "550034")	{
				
				//validate email field using regular expression
				$normal = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^"; 
				$validButRare = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$^";
				$email = $_POST["element_4"];
				if (preg_match($normal, $email)===1)  {
					$email = $_POST["element_4"];
				}
					else if (preg_match($validButRare, $email)===1)	{
						$email = $_POST["element_4"];
						$emailErr = "The address ".$email." looks a bit strange but it is syntactically valid. You might want to check it for typos.";
					}
					else	{
						$email = $_POST["element_4"];
						$emailErr = "Invalid email format";
					}
				
				if ($emailErr <> "Invalid email format")	{	
					//process email for delivery
					
					$sendto = "{your email address}";
					$sendto .= ",";
					$sendto .= $email;
					$subject = $_POST["form_id"];
					
					//assemble email
					$message = "
						<html>
							<body>
								<table border='1' cellpadding='2'>
									<tr>
										<td>Form ID</td>
										<td>$form_id</td>
									</tr>
									<tr>
										<td>First Name</td>
										<td>$element_2_1</td>
									</tr>
									<tr>
										<td>Last Name</td>
										<td>$element_2_2</td>
									</tr>
									<tr>
										<td>Email Address</td>
										<td>$element_4</td>
									</tr>
									<tr>
										<td>Type of Car</td>
										<td>$element_5</td>
									</tr>
									<tr>
										<td>How we can help</td>
										<td>$element_1</td>
									</tr>
									<tr>
										<td>Date needed</td>
										<td>$element_3_1 $element_3_2 , $element_3_3</td>
									</tr>
								</table>
							</body>
						</html>
						";
	
						$mime_boundary = "----BOUNDARY HEADER----".time();
						$headers = "From: $element_2_1 $element_2_2 <$element_4>" . "\r\n";
						$headers .= "Reply-To: $element_2_1 $element_2_2 <$element_4>" . "\r\n";
						$headers .= "Return-Path: {your email address}" . "\r\n";
						$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
						$headers .= "MIME-Version: 1.0" . "\r\n";
						$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
						$headers .= "Organization: {Name of your company}";
						
						mail($sendto, $subject, $message, $headers);
						foreach($_POST as $value)	{
							$value = "";
						}
					}
				}
			}
	}
	//if the form was not submitted, do nothing 
?>
</head>
<body id="main_body" >
	
	<img id="top" src="top.png" alt="">
	<div id="form_container">
	
		<h1><a>AAA1 Hudson Limo</a></h1>
		<form id="form_550034" class="appnitro"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
					<div class="form_description">
			<h2>AAA1 Hudson Limo</h2>
			<p></p>
		</div>						
			<ul >
			
					<li id="li_2" >
		<label class="description" for="element_2">Name </label>
		<span>
			<input id="element_2_1" name= "element_2_1" class="element text" maxlength="255" size="8" value=""/>
			<label>First</label>
		</span>
		<span>
			<input id="element_2_2" name= "element_2_2" class="element text" maxlength="255" size="14" value=""/>
			<label>Last</label>
		</span> 
		</li>		<li id="li_5" >
		<label class="description" for="element_5">Drop Down </label>
		<div>
		<select class="element select medium" id="element_5" name="element_5"> 
			<option value="" selected="selected"></option>
<option value="1" >Sedan</option>
<option value="2" >Limo</option>

		</select>
		</div> 
		</li>		<li id="li_1" >
		<label class="description" for="element_1">How may we help you </label>
		<div>
			<textarea id="element_1" name="element_1" class="element textarea medium"></textarea> 
		</div> 
		</li>		<li id="li_3" >
		<label class="description" for="element_3">Date/when is the special occasion </label>
		<span>
			<input id="element_3_1" name="element_3_1" class="element text" size="2" maxlength="2" value="" type="text"> /
			<label for="element_3_1">MM</label>
		</span>
		<span>
			<input id="element_3_2" name="element_3_2" class="element text" size="2" maxlength="2" value="" type="text"> /
			<label for="element_3_2">DD</label>
		</span>
		<span>
	 		<input id="element_3_3" name="element_3_3" class="element text" size="4" maxlength="4" value="" type="text">
			<label for="element_3_3">YYYY</label>
		</span>
	
		<span id="calendar_3">
			<img id="cal_img_3" class="datepicker" src="calendar.gif" alt="Pick a date.">	
		</span>
		<script type="text/javascript">
			Calendar.setup({
			inputField	 : "element_3_3",
			baseField    : "element_3",
			displayArea  : "calendar_3",
			button		 : "cal_img_3",
			ifFormat	 : "%B %e, %Y",
			onSelect	 : selectDate
			});
		</script>
		 
		</li>		<li id="li_4" >
		<label class="description" for="element_4">Email </label>
		<div>
			<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/> <?php echo $emailErr ?>
		</div> 
		</li>
			
					<li class="buttons">
			    <input type="hidden" name="form_id" value="550034" />
			    
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
		</li>
			</ul>
		</form>	
		<div id="footer">
			</a>
		</div>
	</div>
	<img id="bottom" src="bottom.png" alt="">
	</body>
</html>

Open in new window


You will notice that lines 10-100 are all PHP script elements. These are essential to creating output from your form if you are not going to use hosting service form mailers. As napoleon stated earlier, GoDaddy has a script built for form results, but it is extremely limited as to whom the emails may be delivered (only a single address). When you use the PHP mail() function, you can specify any email address desired.

You will also notice that I included a regular expression method which validates the email address. I found this wonderful snippet elsewhere and love it.

You will still need to sift through the code to find places in curly braces {  } where I have put a place holder for your personal information. Specifically in the header for your email address and your organization name.

Also notice that I modified your form action to read: action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" . This makes your page self-processing.

IMPORTANT!! -- you will need to save your file as a PHP, not HTML, in order for these processes to work properly. Otherwise, you will need to place the PHP script into a separate file and point to it from your form action=""

Additional note: You should rename your form names/id's with more intuitive names instead of element**_**. It makes your scripting a bit easier since you won't need to be constantly checking a reference sheet to find which variables are which.
0
 
imagekrazyAuthor Commented:
thank you
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now