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! :)

Recommended Answers

All 2 Replies

#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

Good Code :)

For larger files i use phpmailer-fe :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.