如何使用表单(html)和php发送消息发送消息?

I am using this form code in html to make a contact form on my website:

<form method="post" action="contact.php">
    <p>
        <label for="name">Name</label>
        <input type="text" id="name" name="name" />
    </p>
    <p>
        <label for="email">Email</label>
        <input type="text" id="email" name="email" />
    </p>
    <p>
        <label for="message">Message</label>
        <textarea id="message" name="message" rows="6" cols="30"></textarea>
    </p>
    <p>
        <input type="submit" name="send" value="Send message" />
    </p>
</form>

This is the php code that I'm using to get the contact form sent to my email address:

<?php
   if(isset($_POST['send'])) {
   // Prepare the email
   $to = 'someone@example.com';
   $subject = 'Message sent from website';
   $message = $_POST['message'];
   // Send it
   $sent = mail($to, $subject, $message);
   if($sent) {
   echo 'Your message has been sent successfully!';
   } else {
   echo 'Sorry, your message could not send.';
   }
   }
?>

I cannot get it to send to my email address. I've made it live to try it but it still doesn't work and I don't know what I'm doing wrong. How can I get the user the send the email to my email address - have it sent to my email address so that I can see the message in my email? (Please help)

Your code checks out. The only thing (or one of possibly other unknown factors at this time) I can see that could affect it is, that you don't have a From: in your mail headers which may be ignored or sent to Spam; this is entirely possible and I have seen it happen before.

Try the following with added header for From: and the person who sent it.

(Tested on my hosted server, and sent to Inbox)

<?php

if(isset($_POST['send'])) {
   // Prepare the email
$to = 'someone@example.com';

$name = $_POST['name'];
$mail_from = $_POST['email'];
   $subject = 'Message sent from website';
   $message = $_POST['message'];

$header = "From: $name <$mail_from>";

   // Send it
   $sent = mail($to, $subject, $message, $header);
   if($sent) {
   echo 'Your message has been sent successfully!';
   } else {
   echo 'Sorry, your message could not send.';
   }
}
?>

This code Work 100% Try this code in PHP. Then upload it in your hosting site. Because email does not work on local. So you need to upload it. Happy Coding.!!!

    <?php 
     $to ='santoshdevnath15@gmail.com';
     $from = 'santoshdevnath15@gmail.com';
     $subject = 'Html Eamil Check';
     $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Untitled Document</title>
                </head>

                <body>
                <div style="width:400px; height:400px; background-color:#096; color:#FFF">
                <h1>Welcome to inet shopping site</h1>
                <p>
                Dear Santosh,
                We have received your Cash-On-Delivery order. We need to confirm your order by call. We will get in touch with you soon on Your order               will be processed only after confirmation.
                For the payment, please pay Rs. 4000 cash to the courier person when he delivers the product.
                "Please call us on 8882248819 to confirm after you deposit the amount."
                </div>
                </body>
                </html>';
    $headers = "From: $from
";
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-type: text/html; charset=iso-8859-1
";
    if(mail($to, $subject, $message, $headers)){
        echo 'ok';
    }
    else{
        echo 'error';
    }

?>