简单的PHP电子邮件表单无效

Very simple email form code. Worked once, but won't work anymore, even at different addresses. That is to say the emails no longer show up, but I'm not erroring out eather.

<form action="/mail-us.php" method="POST">
    <p>Name</p> <input type="text" name="name">
    <p>Email</p> <input type="text" name="email">
    <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

And here is the PHP

<?php $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent="From: $name 
 Message: $message";
    $recipient = "blah@x-matic.net";
    $subject = "X-Matic Contact Form";
    $mailheader = "From: $email 
";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error sending email!");
?>

Note, I tested the email out with my gmail account (from gmail to email, instead of from form to email) and it worked.

Use SMTP mail when in localhost, and switch to mail() once the site is in a webserver (i.e your webhost)

At least that is what i do.

Unless you want to install Pegasus Mail on your computer, the mail() function will not work on your localhost computer, as your computer does not have a mail server installed.

Either that, or use SMTP.

if(isset($_POST['submit']))
{
    $to = "xxx@google.com";
    $subject = "Email from Sender; // quotation marks end ;
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];
    $body = "From: $name_field
 E-Mail: $email_field
 Message:
 $message";

    mail($to, $subject, $body);
}
else
{
    echo "Mail sending Failure!";
}
?>

try this