我正在尝试将所有输入到我网站上的表格中的数据发送到我的电子邮箱中,但似乎无法让它工作......
这是我的email.php文件..
<?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"
}
?>
我的HTML代码......
<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>
当我测试它时,在我在表单中输入一些数据并提交后,它只是在浏览器中显示php代码。
答案 0 :(得分:1)
尝试获取此类值
$Name = trim(stripslashes($_POST['Name']));
$Email = trim(stripslashes($_POST['Email']));
$Message = trim(stripslashes($_POST['Feedback']));
因为你在表格中给出了以大写字母开头的名字。
答案 1 :(得分:0)
确保
echo $EmailTo.$Subject.$Body;die;
显示正确的值,则将"From: <".$EmailFrom.">"
置于邮件功能行中。