有人能告诉我代码是否有问题或更好的修改方法?出于某种原因,当我点击我的联系表单上的提交时,它显示“error.html”页面,但我仍然收到一封发送到我帐户的电子邮件。
$EmailTo = "example@example.com";
$Subject = "Contact Submission";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Budget = Trim(stripslashes($_POST['budget']));
$Message = Trim(stripslashes($_POST['message']));
// prepare email body text
$Body = 'Contact Submission'."\n";
$Body .= 'Name: ' .$Name."\n";
$Body .= 'Email: ' .$Email."\n";
$Body .= 'Budget: ' .$Budget."\n";
$Body .= 'Message: ' .$Message."\n";
// send email
$success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>");
// redirect to success page
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
if ($success){
header ('location:thankyou.html');
}
else{
header ('location:error.html');
}
答案 0 :(得分:8)
更改
if ($success){
到
if ($success_email){
$ success 不存在......
答案 1 :(得分:0)
$EmailTo = "example@example.com"; $Subject = "Contact Submission"; $Name = Trim(stripslashes($_POST['name'])); $Email = Trim(stripslashes($_POST['email'])); $Budget = Trim(stripslashes($_POST['budget'])); $Message = Trim(stripslashes($_POST['message'])); // prepare email body text $Body = 'Contact Submission'."\n"; $Body .= 'Name: ' .$Name."\n"; $Body .= 'Email: ' .$Email."\n"; $Body .= 'Budget: ' .$Budget."\n"; $Body .= 'Message: ' .$Message."\n"; // send email $success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>"); // redirect to success page // CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE if ($success_email){ header ('location:thankyou.html'); } else{ header ('location:error.html'); }
答案 2 :(得分:0)
//Checking for empty for redirecting error page
if(empty($Name) || empty($Email)||empty($Budget))
{
header('Location:error.html');
exit;
}
//Send the email! if the fileds are not empty
mail($EmailTo, $Subject,$Body,"From: <$Email>");
//One the email is sent, Redirect to thankyou page.
header('Location: thankyou.html');