iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
May 14, 2008
Web Editor Reviews - 6 New Reviews
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP /Email Systems

Contact Form: PHP and mail(); 

  Views:    9395
  Votes:    3
by Kirill Talanov 11/21/03 Rating: 

Synopsis:

Have you ever wondered how the automated feedback forms work? Ever wanted to make one for yourself? Creating a mailer form is easier than you think and this tutorial will guide you through the process.
Pages: firstback2 forwardlast
The Article

A contact form is essential to any website, business or personal. It allows the visitor to communicate with the webmaster and offer feedback and suggestions.

Without further ado, let's take a look how you can create your own contact form with PHP: it's easier than you think!

Let's name this file "contact.php" and start coding:

 <html><head> <title>My PHP Mailer</title></head><body>

The html/head/body tags are a necessary part of every webpage, and now that we have that out of the way we can start creating the form.

 <form name="mailer" method="post" action="mail.php">

This line tells us that a form is following, and to submit the form to a file called "mail.php". The mail.php file will be constructed on the next page, so don't worry about it just yet.  Also note the 'method="post"' line, this tells us that the variables (data submitted through the form) will be sent using POST instead of GET (if you don't know the differences between POST and GET don't worry, that's another subject altogether). 

<p>Your name:
    <input name="name" type="text" id="name">
</p>
  <p>Your comments:<br>
    <textarea name="comments" cols="20" rows="4" wrap="VIRTUAL" id="comments"></textarea>
</p>

The above creates the actual text fields where the data can be entered. One of the more important attributes is "name" - this will tell PHP what that field is named as, so that the data can be actually used in the next page!

 

<p>
<input name="submit" type="submit" id="submit" value="Submit">
</p>
</form>
</body>
</html>

Now we have created the "Submit" button to take us to the mailing page and "closed" the HTML page. You can customize the text on the button by changing the value attribute if you wish.

But where's the PHP code? I came here to learn PHP!

Don't worry, now that we've laid the foundation we can get to the fun of the actual mailing! But first, let's recap what we've coded in this section:

contact.php

<html>
<head>
<title>My PHP Mailer</title>
</head>

<body>
<form name="mailer" method="post" action="mail.php">
  <p>Your name:
    <input name="name" type="text" id="name">
</p>
  <p>Your comments:<br>
    <textarea name="comments" cols="20" rows="4" wrap="VIRTUAL" id="comments"></textarea>
</p>
  <p>
    <input name="submit" type="submit" id="submit" value="Submit">
</p>
</form>
</body>
</html>

The end product will look something like this:

Ready to go on? Head to page two to complete the script!

Pages: firstback2 forwardlast

Similar/related articles:


 
  Sponsors