HTML表单到PHP邮件无法正常工作[重复]

This question already has an answer here:

I am absolutely bad at PHP programming. I have no experience with it, but I wanted a form on my website with a mail script. So like almost every other person with no experience on a language, I googled up one and customized it.

mail_send.php

<?php 
if(isset($_POST['submit'])){
$to = "my@mailadress.com"; // I just did this for privacy     
$from = $_POST['email'];     
$name = $_POST['name'];    
$subject = "Form submission";    
$message = $name . " " . $from . " wrote the following:" . "

" . 
$_POST['message'];    

$headers = "From:" . $from;    
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>

and here the HTML code: index.html

 <form role="form" id="feedbackForm" class="text-center" action="mail_send.php" method="post">
          <div class="form-group">
            <label for="name">Naam</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
            <span class="help-block" style="display: none;">Voer uw naam in..</span></div>
          <div class="form-group">
            <label for="email">E-Mail</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
            <span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
          <div class="form-group">
            <label for="message">Bericht</label>
            <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
            <span class="help-block" style="display: none;">Voer een bericht in.</span></div>
          <button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
        </form>

So I have uploaded both files to my Website Server so I've tested it online, but still without success. Any smart guys being able to help me?

Thanks in advance :)

</div>

Please modify button tag

<button type="submit"  name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>

Use name = submit in button tag.

<button type="submit"  name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>

After that also check your spam folder. Sometime you don't get messages in inbox.

  1. I suggest to do not use mail function directly. Better use something like https://github.com/PHPMailer/PHPMailer and use it through SMTP of a real e-mail account of yours.
  2. You are checking in your IF clause $_POST['submit'] - But I don't see where did you set this name="submit" in your html code... you need to add name="submit" to your button

Modify as per your requirement and I hope this code will send you message to inbox directly rather than span

<?php 
    if(isset($_POST['submit'])){
        $to = "Email Address Here"; // I just did this for privacy     
        $from = $_POST['email'];     
        $name = $_POST['name'];    
        $subject = "Form submission";    
        $message = $name." ".$from." wrote the following:". "

". $_POST['message'];    

        $headers = "MIME-Version: 1.0" . "
";
        $headers .= "Content-type:text/html;charset=UTF-8" . "
";   
        $headers .= 'From: <info@example.com>' . "
";

        mail($to,$subject,$message,$headers);
        echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title>Mail Example</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

     <form role="form" id="feedbackForm" class="text-center" action="" method="post">
          <div class="form-group">
            <label for="name">Naam</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
            <span class="help-block" style="display: none;">Voer uw naam in..</span></div>
          <div class="form-group">
            <label for="email">E-Mail</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
            <span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
          <div class="form-group">
            <label for="message">Bericht</label>
            <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
            <span class="help-block" style="display: none;">Voer een bericht in.</span></div>
          <button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
        </form>
</body>
</html>