0

I have a small website,I have created html page having form in it.the form contains 3 text boxes that is.. name,email,comment.I need an e-mail script that can submit this form fields to my gmail or yahoo account.I have tried lots of script on internet but they are not working.Can anyone kindly tell me how to do that.
THANKS! :)

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by DonaldAlexander
0

#1 - On your form tag, set method="post" and set action="yourphpfilename.php"

#2 - Replace yourphpfilename with the name of your php file that is going to collect the data from the form and send it through mail (eg : form.php)

#3 - On your html form, set name property for name, email and comments:
eg : <input type="text" name="name" />

#4 - In your php file, form.php in our example, provide the following code:

<? 
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$to = "test@gmail.com";
$from="$email";
$subject='Testing form';

$message="<table width='100%' class='table'>
    <tr><td height='15px'></td></tr>
	    <tr><td colspan='3'>Testing form</td></tr>
    <tr>
    <td width='266'><label>Name</label></td>
    <td width='266'>".$name."</td>
    <td width='266'></td>
  </tr>
  <tr>
    <td width='266'><label>Email-id</label></td>
    <td width='266'>".$email."</td>
    <td width='266'></td>
  </tr>
  <tr>
    <td width='266'><label>Comments</label></td>
    <td width='266'>".$comments."</td>
    <td width='266'></td>
  </tr>
</table>";

//populate the header filed
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$from . "\r\n";

mail($to,$subject,$message,$headers);
?>

Note :
a) The values provided within $_POST should be the values provided in the name tag as described in #3 above
b) I have listed only the very basic steps required. You will have to work on validations and other details for the form to be secure

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.