简体   繁体   English

联系表格提交错误

[英]Contact form submit error

I've got a simple contact form set up, but am having a little trouble with the finishing touches. 我已经建立了一个简单的联系表单,但是最后的处理有点麻烦。 I'm getting an error message whenever the form is submitted. 每当提交表单时,我都会收到一条错误消息。 Was hoping someone can take a look at my code and point out my mistake. 希望有人可以看看我的代码并指出我的错误。 Thanks! 谢谢!

(edited) Forgot to mention the error is that once form is submitted, I am being redirected to the error page (error.html) instead of the success (contactthanks.php) page. (已编辑)忘记提了错误,因为提交表单后,我将被重定向到错误页面(error.html),而不是成功页面(contactthanks.php)。

HTML: HTML:

<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />

<label for="City">City:</label>
<input type="text" name="City" id="City" />

<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />

<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>

<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>

PHP: PHP:

<?php

$EmailFrom = "";
$EmailTo = "MYEMAIL@gmail.com";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 


$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}


$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";


$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}

It is redirecting to your error page because the call to mail is returning false (indicating the email was not accepted for delivery) and that is exactly what you are telling it to do in that situation. 它正在重定向到您的错误页面,因为对mail的调用返回了false (指示电子邮件不被接受发送),而这正是您在这种情况下要执行的操作。

You need to check the SMTP set up on your server. 您需要检查服务器上的SMTP设置。

Typically the settings to check for are sendmail_from and sendmail_path in your PHP.ini file. 通常,要检查的设置是PHP.ini文件中的sendmail_fromsendmail_path Seeing as you are already setting a From header, sendmail_path is likely to not be set up correctly. 似乎您已经设置了From头,则sendmail_path可能设置不正确。

See what's causing the problem with 看看是什么原因引起的

ini_set("display_errors", "1"); 
error_reporting(E_ALL);`. 

My guess is you have wrong smtp settings and mail function fails. 我的猜测是您的smtp设置错误并且mail功能失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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