Where Knowledge Rules

Computers & Technology:

Internet

Get a Widget for this title

How to use PHP to send form information by email

by Gareth

To send form information via the PHP mail() function you will first need to create a page with a form on.

The HTML you need for the form is below, replace [ with < and ] with > since it's not possible to post HTML.

[form method="POST" action="savecomment.php"]
Real Name: [br][input type="text" name="realname" size="20"][br]Email Address: [br][input type="text" name="email" size="20"][br]Message: [br][textarea rows="3" name="message" cols="18"][/textarea][br][br][ input type="submit" value="Submit" name="send"]


[/form]

That can go in any page, although it must be in the same directory as the next page you are creating. We then need to create a PHP page, name it savecomment.php

Inside this file we put the following coding:

<?php

mail("your_email@whatever. com", "Message Received From " . $_POST['realname'], $_POST['message'], "From: " . $_POST['email']);

echo "Message sent, thanks!";

?>

Replace your_email@whatsover.com with the email address you would like to receive the emails on. Also note this is a very simple code for beginners and doesn't check to see if the email has been sent or not, and only displays the default PHP errors, not our own neat ones.

Remember, both these pages must be in the same directory otherwise you will have to change the URL to send the form data to in the HTML.

Now all you need is a web server/host with PHP installed. Then upload the files onto them. You can't do this on services such as Geocities or simple HTML hosts.

Try it out for yourself, and see if it works, if not, check back through the steps.

Learn more about this author, Gareth.
Contact this writer Click here to send this author comments or questions.


Below are the top articles rated and ranked by Helium members on:

How to use PHP to send form information by email

  • 1 of 2

    by Mia Lee

    If you are a web developer or web designer, then you may have needed to capture a user's information from a web page, and

    read more

  • 2 of 2

    by Gareth

    To send form information via the PHP mail() function you will first need to create a page with a form on.

    The HTML you need

    read more

Add your voice

Know something about How to use PHP to send form information by email?
We want to hear your view. Write_penWrite now!

Helium Debate

Cast your vote!

Is Wikipedia a threat to Google?

Click for your side.

171851

Featured Partner

Dogs Deserve Better

Dogs Deserve Better has partnered with Helium, giving you the chance to write for a cause. Browse Dogs Deserve B...more

What is Helium? | Buy Web Content | Contact Us | Privacy | User agreement | DMCA | User Tools | Help | Community | Helium’s Official Blog | Link to Helium

Helium, Inc.
200 Brickstone Square Andover, MA 01810 USA