如何为我现有的网站创建电子邮件反馈表单? [关闭]

Users fill the feedback form and send mails to us. I wnat to ue php mail() function. please help how to use the php script? what are the things i need for that?

I am new to this, can you please help me?

My form code:

<form name="contact" method="post" action="sendmail.php" enctype="multipart/form-data" onsubmit="return checkForm(this);">
<table style="width:100%;height:40px;"><tr><td align="right"><span id="error" style="color:#FF0000;">&nbsp;</span></td></tr></table>
<label><span>First Name:</span><input type="text" name="fname" id="fname"/></label>
<label><span>Last Name:</span><input type="text" name="lname"/></label>
<label><span>Email Address:</span><input type="text" name="email"/></label>
<label><span>Phone No. :</span><input type="text" name="phone"/></label>
<label class="last"><span>Feedback :</span><textarea name="message" cols="" rows=""></textarea></label>
<label class="btnsub"><input name="" type="submit" title="submit" class="submission"/></label>
</form>

Sendmail.php

<?php
if (isset($_POST['sendmail'])) {
    //catch and validate user inputs
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $phone = $_POST['phone'];

    //send mail using php's mail function
    $to      = 'tomail@gmail.com';
    $subject = 'FeedBack';
    //appended extra information just to show that you can do it like this way
    $message = $fname. " " . $lname .", " . $_POST['message'] . $phone;
    $headers = 'From:' . $_POST['email']. "
" .
        'Reply-To:' . $_POST['email'] ."
" .
        'X-Mailer: PHP/' . phpversion();

    // Please specify your Mail Server - Example: mail.yourdomain.com.
    //If you are testing on localhost, then make sure that mailserver is running on localhost
    ini_set("SMTP","localhost");

    // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
    ini_set("smtp_port","25");

    mail($to, $subject, $message, $headers);
    //refer this URL:http://php.net/manual/en/function.mail.php
}
?>

NOTE : You should never use users input directly in script. NEVER. I have just shown you an example of how you can use mail function and not the entire process. Please validate users input before using it in script. You can get better idea from the URL i have mentioned above.

If you are taking some information from user like Firstname and Lastname and Phone number then its better that you pass it somehow in email to you. So, i have updated answer to give you idea about that.