- Impact
- 0
OK,
I posted this reply to many people that wanted a bit of help with their form and decided to package it up here for all to benefit from a nice quick and easy to implement php form script that will process unlimited fields in a form, you just have to name them in the HTML side of things, it doesn't get any easier if you are just starting out. OK, here we go:
First off, copy the text below and save this as formscript.php (you can name it anything but for this example thats what I will call it :D ) Simply change the details in the "$To", "$From" and "$Subject" fields below to suit, I have bolded them below also to make it easier.
Now ... you just change the address near the bottom of this script just after "header("location:" part that is in bold below to either, your homepage or a "thank you" page that says, "thanks" and confirms the eMail has sent then re-directs to where you want it too, usually your homepage (again ... I have made the code bold where you have to change it slightly to suit but it pretty straight forward, honest!)
Here is the PHP Script:
OK ... Now, in your form tags on your .html page, set the action to point to the page you just saved, here is an example of how the top of your form would like:
This is where the script becomes very easy for even newbies, all you have to do now is make sure you name the text fields, check boxes, list boxes etc with appropriate names. Here is an example with a table inside our form above with the names set as I would want them, copy and paste this code into a blank .html file if you want so you can see it laid out visually if you need to:
NOTE: for the eMail to come through as the senders name and eMail, make sure you have a field named "name" and one named "email" to reflect the php script right at the top, see below
I hope that has not confused you, I am just trying to be very thorough here :D
The above code I have used in forms for a few years now on many contact pages and has never let me down, to give you an instant idea of how it formats here is an eMail form my hosting site a while ago now:
So, do you see the php code at the top working down here now? If you can see it working you will realise you can have any number of fields, boxes and lists in your form and the php script will process them all.
Just make sure you name them appropriately to make sense of your questions being answered from your form. I hope this helps someone out there looking for a simple solution like this and if I have seemed to of rushed my explanation and you are still confused, reply to this thread for a prompt reply.
Warm Wishes,
I posted this reply to many people that wanted a bit of help with their form and decided to package it up here for all to benefit from a nice quick and easy to implement php form script that will process unlimited fields in a form, you just have to name them in the HTML side of things, it doesn't get any easier if you are just starting out. OK, here we go:
First off, copy the text below and save this as formscript.php (you can name it anything but for this example thats what I will call it :D ) Simply change the details in the "$To", "$From" and "$Subject" fields below to suit, I have bolded them below also to make it easier.
Now ... you just change the address near the bottom of this script just after "header("location:" part that is in bold below to either, your homepage or a "thank you" page that says, "thanks" and confirms the eMail has sent then re-directs to where you want it too, usually your homepage (again ... I have made the code bold where you have to change it slightly to suit but it pretty straight forward, honest!)
Here is the PHP Script:
<?
$To = "[email protected]";
$From = "Whoever You Want Here <[email protected]>";
$Date = date("d/m/Y");
if (!$Subject) {
$Subject = "An eMail on $Date from Your Website";
}
$Body = "On $Date, an enquirey was made at the Your Website \n".
"The following information was submitted:\n\n";
foreach ( $HTTP_POST_VARS as $key => $value ) {
if ($key=="Submit") continue;
$Body .= "$key: $value\n";
}
if (mail($To,$Subject,$Body,"From: $name <$email>")) {
header("location: http://www.yourwebsite.com/your-thank-you-page.htm");
} else {
echo("Could not process your order.<br>".
"Please try again later<br>".
"We are sorry for any inconvenience");
exit();
}
?>
OK ... Now, in your form tags on your .html page, set the action to point to the page you just saved, here is an example of how the top of your form would like:
<form action="http://www.yourdomain.com/formscript.php" method="post" name="contact-form">
<!-- content in here -->
</form>
This is where the script becomes very easy for even newbies, all you have to do now is make sure you name the text fields, check boxes, list boxes etc with appropriate names. Here is an example with a table inside our form above with the names set as I would want them, copy and paste this code into a blank .html file if you want so you can see it laid out visually if you need to:
NOTE: for the eMail to come through as the senders name and eMail, make sure you have a field named "name" and one named "email" to reflect the php script right at the top, see below
<form action="http://www.yourdomain.com/formscript.php" method="post" name="contact-form">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr valign="middle">
<td width="22%" height="18">
<div align="right">Name</div>
</td>
<td width="78%">
<input name="name" type="text">
</td>
</tr>
<tr valign="middle">
<td width="22%" height="18">
<div align="right">eMail</div>
</td>
<td width="78%">
<input name="eMail" type="text">
</td>
</tr>
<tr valign="middle">
<td width="22%">
<div align="right">Subject</div>
</td>
<td width="78%">
<select name="subject">
<option selected>Please Choose One</option>
<option>-------------------</option>
<option>General </option>
<option>Accounts </option>
<option>Sales </option>
<option>Custom Quote</option>
<option>Multiple Domain Hosting</option>
<option>Reseller Plans</option>
<option>Domain Registration</option>
<option>Add Link</option>
<option>Lost My Password</option>
<option>-------------------</option>
<option>Other</option>
</select>
</td>
</tr>
<tr valign="middle">
<td width="22%">
<div align="right">If Other</div>
</td>
<td width="78%">
<input name="if_other" type="text">
</td>
</tr>
<tr valign="middle">
<td width="22%">
<div align="right">Message</div>
</td>
<td width="78%">
<textarea name="message" cols="40" rows="10"></textarea>
</td>
</tr>
<tr valign="middle">
<td width="22%"> </td>
<td width="78%">
<p>
<input name="reset" type="reset" value="Clear Form">
<input name="send" type="submit" value="Send eMail">
</p>
</td>
</tr>
</table>
</form>
I hope that has not confused you, I am just trying to be very thorough here :D
The above code I have used in forms for a few years now on many contact pages and has never let me down, to give you an instant idea of how it formats here is an eMail form my hosting site a while ago now:
On 23/03/2004, an enquirey was made at the Total Host contact page
The following information was submitted:
name: John Weare
eMail: edited for client safety
subject: Multiple Domain Hosting
if_other:
message: Wanted to ask two questions. 1.) my client wants to have hisdomain.co.nz and hisDomain.com come to the same web address. Would there be additional charges for this usned the basic $10.00/mo plan 2.) Second question, what would be the domain registration and renewal costs for .co.nz and .com domains.
Cheers,
John Weare
send: Send eMail
So, do you see the php code at the top working down here now? If you can see it working you will realise you can have any number of fields, boxes and lists in your form and the php script will process them all.
Just make sure you name them appropriately to make sense of your questions being answered from your form. I hope this helps someone out there looking for a simple solution like this and if I have seemed to of rushed my explanation and you are still confused, reply to this thread for a prompt reply.
Warm Wishes,
Last edited: