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.
Click here to send this author comments or questions.
Below are the top articles rated and ranked by Helium members on:
Add your voice
Know something about How to use PHP to send form information by email?
We want to hear your view.
Write now!
Featured Partner
Dogs Deserve Better has partnered with Helium, giving you the chance to write for a cause. Browse Dogs Deserve B...more
hide