2torial Blog|photoshop tutorials, website design tutorials and graphic design articles and tutorials

2torial Blog RSS

E-mail form using HTML and PHP

Filed Under (Forms, Web Design) by Dave on 05-01-2008

Tagged Under : html & php mail form, mail form, php e-mail script

Sometimes it’s a nice touch to include an e-mail feedback form on your contact page or elsewhere on your web site. Let’s create an e-mail form using html and a simple php script to send it along. The first thing to do is create the form using html. We’ll call it feedback.html. The form will have an action of send.php, which we’ll create later. Below is the html code for our form:

<html>
<head>
<title>E-mail Form</title>
</head>
<body>
<form action=”send.php” method=”POST”>
<p>Name:<br /> <input type=”text” size=”20″ name=”name” /></p>
<p>E-Mail Address:<br /> <input type=”text” size=”20″ name-”email” /></p>
<p>Message:<br />
<textarea name=”message” cols=”30″ rows=”5″></textarea></p>
<p><input type=”submit” value=”send” /></p>
</form>
</body>
</html>

Notice the size=”20″ field we added for the name and email fields. This is the character width for the input box. The higher the number the wider the input box. The same applies for the textarea field. Increasing the value of col=”30″ will widen the box. Increasing the value of rows=”5″ will lengthen the box.

Put these lines in a text file called feedback.html and place the file in the root directory of your web server. After doing this, the form should look something like the image below:

Now let’s create the script to send the mail. Put the following lines into a text file called send.php and upload it to the root directory of your web server. DO NOT include the numbers or the period at the beginning of each line.

1. <html>
2. <head>
3. <title>Script to send mail</title>
4. </head>
5. <body>
6. <?php
7. echo “<p>Thank you, <b>$_POST[name]</b>, Your message has been sent.</p>”;
8. //start building the mail string
9. $msg = “Name; $_POST[name]\n”;
10. $msg .= “E-Mail: $_POST[email]\n”;
11. $msg .= “Message: $_POST[message]\n”;
12. $recipient = “you@yourdomain.com”;
13. $subject = “Form Submission Results”;
14. $mailheaders = “From: My Website <you@yourdomain.com> \n”;
15. $mailheaders .= “Reply-to: $_POST[email]“;
16. //send the mail
17. mail($recipient, $subject, $msg, $mailheaders);
12. ?>
13. </body>
14. </html>

Lines 9-11 create the $msg variable, a string containing the values typed by the user in the form fields. This is essentially one long message string using the (\n) character to add line breaks where appropriate.

Lines 12 and 13 are the variable naming the recipient and the subject of the email, make sure to put your own e-mail address here and change the subject to whatever you want.

Lines 14 and 15 sets up the: From: and Reply-to: mail headers

Line 17 is the mail( ) function and sends the four parameters: recipient, subject, message and mail headers to your email.

That’s it! A very simple e-mail form that can be used over and over.

Share and Enjoy:
  • StumbleUpon
  • Digg
  • Technorati
  • del.icio.us
  • Facebook
  • YahooMyWeb
  • Google Bookmarks
  • blogmarks
(6) Comments
Read More

Comments

  1. Html Tutorials In Web Page Design. | 7Wins.eu said...
    Posted on: 20/Jun/2008 at 05:06

    [...] [...]

  2. Kiran said...
    Posted on: 15/Feb/2009 at 12:02

    form is not working.. getting error..see below

    Notice: Undefined index: name in C:\wamp\www\meenas\send.php on line 7

    Thank you, , Your message has been sent.

    Notice: Undefined index: name in C:\wamp\www\meenas\send.php on line 9

    Notice: Undefined index: email in C:\wamp\www\meenas\send.php on line 10

    Notice: Undefined index: email in C:\wamp\www\meenas\send.php on line 15

    Warning: mail() [function.mail]: SMTP server response: 550 Access denied – Invalid HELO name (See RFC2821 4.1.1.1) in C:\wamp\www\meenas\send.php on line 17

  3. Dave said...
    Posted on: 15/Feb/2009 at 02:02

    Include your entire script for the send.php so I can take a look. also, just in case you haven’t, PHP scripts will only work when running off of your server so you must upload the feedback.html and the send.php to your sever.

  4. Neil Burge said...
    Posted on: 10/Mar/2009 at 08:03

    Kiran – You need to configue your settings in wamp for using the mail( function

  5. dorow said...
    Posted on: 2/May/2009 at 12:05

    I looking for step by step on how email useing ASP.net VB and Asp.Net need help badly

  6. rohit said...
    Posted on: 21/Jul/2009 at 10:07

    hi how are you

Leave a Reply

Search:
Graphic Design Blogs - Blog Catalog Blog Directory Join My Community at MyBloglog! blogarama - the blog directory Add to Technorati Favorites
  • September 2010
    S M T W T F S
    « Dec «-»  
     1234
    567891011
    12131415161718
    19202122232425
    2627282930  
  • Categories

    • After Effects (3)
    • Photoshop (18)
      • Graphic Design (11)
      • Navigation (1)
      • Photo Manipulation (1)
      • Text Effects (5)
    • Web Design (7)
      • CSS (3)
      • Dreamweaver (2)
      • Forms (2)
      • Web Navigation (1)
  • Recent Posts

    • Age Progression
    • Photoshop Brushes
    • Photoshop Matte Painting
    • Create a Horror Face in Photoshop
    • Create a Planet and Outer Space Scene
    • 3D Photoshop text tutorial
    • Photoshop Displacement effects
    • Photo Effect – fade into line drawing
  • Archives

    • December 2008
    • November 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
  • Pages

    • About
    • Contact
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Tags

    3 column layout 3d text Absolute Positioning After Effects Expressions After Effects shatter award winning web design Blend modes cool text effects create planet CSS CSS in Dreamweaver CSS menu Displacement effects Displacement Maps Dreamweaver tutorials form validation Grapic Design html & php E-mail form html & php mail form Image effects mail form Photo Effects Photoshop Photoshop & Dreamweaver Photoshop brushes Photoshop buttons photoshop displacement map Photoshop text effects Photshop Matte Painting php e-mail script PHP email script print ad design Space scene Vanishing point filter vista style menu web design colors website navigation Zombie Face
© All Rights Reserved. 2torial Blog