我正在使用以下内容让联系页面向我发送包含访问者数据的电子邮件。
<form method="post" action="submit.php">
<label for="Name">Name</label>
<input type="text" name="Name" id="Name" />
<label for="Email">eMail</label>
<input type="text" name="Email" id="Email" />
<input type="submit" name="submit" value="Send" class="submit-button" />
</form>
和PHP:
<?php
$EmailFrom = "Me";
$EmailTo = "me@me.com";
$Subject = "Test";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "eMail: ";
$Body .= $Email;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
尝试时,我只得到 PHP 文件准备的电子邮件正文,但没有访问者插入的信息,如下所示:
姓名: 电子邮件: