嗨,我有点新的PHP,我正在尝试创建此联系表单。我遇到的一个问题是电子邮件字段被用作接收者电子邮件而不是scpianolessons.ie@gmail.com
任何人都可以看到我出错的地方吗?
感谢。
<?php
$Email = Trim(stripslashes($_POST['Email']));
$Name = Trim(stripslashes($_POST['Name']));
$Number = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=../php/contactthanks.php\">";
exit;
}
// prepare email body text
$to = "$Email";
$from = "scpianolessons.ie@gmail.com";
$subject = "Piano Lessons";
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Number: ";
$Body .= $Number;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($to, $Subject, $Body, "From: <$Email>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=../php/contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
答案 0 :(得分:0)
从你说你的电子邮件也应该是:
$success = mail($to, $subject, $Body, "From: <$from>");
答案 1 :(得分:0)
您引用了错误的变量,请更改
$success = mail($to, $Subject, $Body, "From: <$Email>");
到
$success = mail($to, $Subject, $Body, "From: <$from>");