Sending Form Data via Email

If you don't feel like messing with CGI scripts and can deal with not having your data perfectly formatted (or pre-processed by a script), you can have a visitor's data be sent to you via email.

Figure 17.6. Here is a script used to send form data via email. You can find a commented version of this script on my Web site.

To send form data via email:


Type <form method="post".


Type action="emailform.php", where emailform.php is the script that will send the form data to your email.


Type >.


Create the form's contents, as described on pages 262280.


Type </form>.


  • You might want to ask for the email address to be entered twice, in order to prevent typos from keeping you from receiving the form data. Then have the script compare the two fields and return an error if they're not identical.

    Figure 17.7. This form is almost identical to the other except for an added email field.

  • You can find the code for this script on my Web site (see page 26). You are welcome to use it on your own site.

    Figure 17.8. It's always a good idea to give your visitor feedback about what just happened since they can't see the email wending its way to you.

  • In earlier editions of this book, I offered a technique that used enctype="text/plain" along with an action attribute set to an email address in order to receive form data via email. Unfortunately, it didn't work with some email programs (like Outlook) and so I substituted it for the PHP script shown here.

  • If this script doesn't work on your server, it may be that your server doesn't have PHP installed. Contact your Web host and ask them (or check their Support pages).

    Figure 17.9. Here is the email that was received after the form was submitted in Figure 17.7.

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: