|
Email Forms in PHP
Dan Ball
I recently admitted to myself that my home business should be moved off of
the "free hosting" service I have had it on for about 3 years. Though the service was great,
and it was very feature-rich as compared to any other free service I have seen, it is still
subject to invasive maneuvers by the company itself. That said, I moved to a pay service.
The immediate thrill was no banner code to add to my pages. The underlying benefit was their
support of PHP (PHP Hypertext Preprocessor) pages and hosting a MySQL database. I knew when
I signed up that they supported that; what I didn't know was how great that combination was,
and how powerful PHP really is.
With this "rebirth" I have found in Web development with my introduction to
PHP I have decided to dedicate a little bit of my time and a few pages to PHP and how easy
it is to setup a very cool email feedback form with it. I have used various tools in the
past to build forms and database connectivity, such as ASP, JSP and CGI/Perl. PHP, without a
doubt, has been the most enjoyable to work with yet, with its familiar scripting syntax and
predictable results.
Barebones PHP basics
A couple very basic concepts of PHP must be discussed before getting into
this project further. First, PHP code is inserted into pages inside <?php and ?> tags.
Second, any page that contains any amount of those tags should have the .php or .php3
extension. The .php3 extension is for pages that are using features that were new to version
3 of PHP. Check with your system administrator for any rules regarding which extension you
need to use and the tags you need to enclose the code, because PHP is also designed to be
custom configured to fit the way you are comfortable coding. It can be configured to use the
ASP <% %> tags amongst other customizations that are beyond the scope of this
article.
The PHP pages still contain a lot of typical HTML, so your pages will still
need the typical <html>, <body>, etc. they just may not be right at the top like
you are used to seeing because there may be PHP variables and such being defined before the
<html> tag. Also, like JSP and ASP, if you do a view source at the client level, you
will only see the HTML and client-side scripting, because by that time all the PHP has been
read and processed by the server and the resulting HTML is fed to the browser.
With all that being understood, let's get on with the fun stuff.
The Form
Like any email form, the original form itself is quite simple. No great
shakes here, just a standard HTML form with a POST method and the action pointing to the PHP
page that will process the form results.
<form name="form" method="post" action="contact_thanks.php">
<p class="bodymd">Your Name<br>
<input type="text" name="Name">
</p>
<p class="bodymd">Your Email<br>
<input type="text" name="Email">
</p>
<p class="bodymd">Comments or Questions<br>
<textarea name="Comments" rows="5" cols="40"></textarea>
</p>
<p class="bodymd">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Clear Form">
</p>
</form>
This form can be .html, .shtml or whatever you choose; the page that the
results are handed to, however, must be a PHP page.
[ Next Page ]
| Comments: | ||
| Parse error with your script | Chris | 06/24/08 00:29 |
| Emailing form not sending | LuAnne | 03/14/08 23:25 |
| Email Form | Chris | 01/31/08 10:43 |
| Email Forms in PHP - read this first. | Colin McKinnon | 01/30/08 11:58 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


