Mail Form with PHP and HTML |
| Written by DanielRo | |
|
Before starting you should check that your host has PHP support with the mail() function activated. For this you need to create a php file, name it test.php and enter the following code: <? mail(" This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ","test message","This is a test"); ?>
Some hosts take a little longer to send the message, thus you should wait a while for the e-mail to arrive in your inbox.
The HTML FORMFireup your favorite text-editor, create a new file and paste in the following HTML code.
<html xmlns="http://www.w3.org/1999/xhtml">
Save it As: contact_us.html
<form action="send_mail.php" method="post">
Name: <input type="text" name="name" size="30" /><br />
<input type="submit" name="submit" value="Send" /> The PHP script file - processing the data
Now that we created our HTML form we need to script the PHP file that will process the sent data. Remember the <form action="send_mail.php" method="post">, we now need to create that file.
<?php
Save it As: send_mail.php Remember that we used POST in our HTML form when sending data to the PHP script. Now using the extract function we will recieve the POST data sent and PHP will translate it into single-word variables. @extract($_POST); In the next lines we use the stripslah function to remove any non-alfanumeric characters from the user inputed data, thus making it user friendly.
$name = stripslashes($name); Now by using the mail() function, we are putting it all together. The mail() function collects all the data and sends it to the e-mail address you specify. mail(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ',$subject,$text,"From: $name <$email>"); After the users hits the Submit button, and the mail is sent, this message will be shown on the page. echo("Thank you for your interest, your e-mail was sent.");
You can also download the php e-mail form files.
written by Waseem Hassan , August 08, 2007
This is nice tutorial for sending email with php
written by Luke , September 22, 2007
Gdgd (y)
written by HNX , December 05, 2007
i need somebody to explain how it works
written by Himani , January 23, 2008
i tried it but some internal server error occurred.. can u tel me how to resolve it?
written by liezel , February 27, 2008
Good day, i am a new user of php and mysql. Now i start to develop website for our school IGP(Income generating project) which features clients registration, product ordering and hostel reservation..my problem now is how to insert mail() function on the system which enables the system to send mail to the users email whenever they register,order, reserve hostel rooms or anytime they will performed any transaction on the igp system.I already had the registration,ordering and reservation but the problem is email function. pls give me idea how mail function on this system will be implemented? Thank you!
written by thiyagarajan , March 17, 2008
i tryed by using your coding to sent message to my mail but it is not working. i changed this code: mail(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ''; document.write( '' ); document.write( addy_text79114 ); document.write( '<\/a>' ); //-->\n This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ,$subject,$text,"From: $name "); as mail(' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ',$subject,$text,"From: $name "); but it is not working. what is the problem?
written by AW , March 24, 2008
You spelt 'stripslash' wrong. (stripslah) You might want to change your tutorial's name; it is misleading and makes the viewer think you deal with HTML being send with your email.
written by thiyagarajan , March 25, 2008
THANK YOU,YOUR MAIL CODING IS NOW WORKING for me.
written by rob , June 17, 2008
thank you for the code it was a great help..
written by P. , July 01, 2008
How do I create a mail form giving the user the ability to select different emails preferably through a dropdown box?
written by krshna , July 04, 2008
Hi, Parse error: syntax error, unexpected T_STRING in /homepages/3/d246704272/htdocs/dsc049447899/send_mail_01.php on line 5 this is the error I got in my website. Can I chat with you offline here. Will post my code.
written by Nitro , July 14, 2008
hello, I`m a new user also on Php and Html. So i was training to send an e-mail from my website that i created on my localhost so could you look up code at the below where i have got mistake? i have got error on the "mail($to, $name, $email, $text, $headers);" Parse error: parse error, unexpected T_STRING in C:...... Thank you,
written by yogesh kandwal , August 06, 2008
Thank you. for this site because i get help from see it's.
written by wow gold , September 04, 2008
I`m a new user also on Php and Html. So i was training to send an e-mail from my website that i created on my localhost so could you look up code at the below where i have got mistake?
written by wow powerleveling , October 11, 2008
So i was training to send an e-mail from my website that i created on my localhost so could you look up code at the below where i have got mistake?
written by wow powerleveling , October 11, 2008
I`m a new user also on Php and Html. So i was training to send an e-mail from my website that i created on my localhost so could you look up code at the below where i have got mistake?
written by Kelly Sly , October 30, 2008
I have tested the PHP mail function and it is working. I downloaded the contact_us.html and send_mail.php files and changed the email address in the script. It says that it sent, but I'm not getting an email from it. The mail error log says the following (From address not in member domain. Message not sent.) Please help!! http://www.yardrat.net/contact_us.html
written by Yasin , December 18, 2008
Explain the purpose of extract($_POST); If necessary create sample pages. Do you need more help? Ask now!
|
|
| Last Updated ( Sunday, 14 October 2007 ) |