无法将我的表单数据发送到我的电子邮件

I'm trying to get all the data entered into the form on my website sent to my email when submitted, but just can't seem to get it to work...

This is my email.php file..

<?php

$EmailFrom = "dcmagpies@hotmail.co.uk";
$EmailTo = "  dcmagpies@hotmail.co.uk";
$Subject = "online form message";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['feedback']));
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("");
exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "Thankyou"

}
?>

My html code...

<form name="contactform" method="post" action="emailphp.php">
    <table width="450px">
<tr>
    <td valign="top">
    <label for="name">Name *</label>
</td>
    <td valign="top">
    <input  type="text" name="Name" maxlength="50" size="30">
</td>
</tr>
<tr>

    <td valign="top"">

    <label for="email">Email *</label>
</td>
    <td valign="top">
    <input  type="text" name="Email" maxlength="50" size="30">
</td>
</tr>

<tr>
    <td valign="top">
    <label for="feedback">Feedback *</label>
</td>
    <td valign="top">
    <input  type="text" name="Feedback" maxlength="150" size="30">
</td>
</tr>

<tr>
    <td colspan="2" style="text-align:center">
    <input type="submit" value="Submit">
</td>
</tr>
</table>
</form>

When i test it, after i enter some data in the form and submit it, it just shows the php code in the browser.

Make sure

  • check you saved php file in .php type
  • put echo $EmailTo.$Subject.$Body;die; if it shows values correct, you a problem in mail function line.
  • try like this "From: <".$EmailFrom.">" in mail function line.

Try to get the values like this

$Name = trim(stripslashes($_POST['Name']));
$Email = trim(stripslashes($_POST['Email']));
$Message = trim(stripslashes($_POST['Feedback']));

as you have given the names starting with capital letter in the form.