简体   繁体   中英

Can't get my form data to send to my email

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 .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM