联系我们表单不需要HTML5 / PHP帮助

时间:2016-03-04 14:36:07

标签: php html5

美好的一天,

新手在这里用PHP。我一直在一个网站(免费模板)上工作,除了代码的“联系我们”部分外,还有其他所有功能。我没有收到任何错误,它只是不发送任何电子邮件到列出的电子邮件或发回给发件人的回复。

以下是代码的HTML方面:

<form id="contact-form" action="php/mail.php">
<div class="control-group">
<div class="controls">
<input class="span6" type="text" id="name" name="name" placeholder="* Your name..."/>
<div class="error center" id="err-name">Please enter your name.</div>
</div></div>
<div class="control-group">
<div class="controls">
<input class="span6" type="email" name="email" id="email" placeholder="* Your email..."/>
<div class="error center" id="err-email">Please enter a valid email adress.</div></div></div>
<div class="control-group">
<div class="controls">
<textarea class="span6" name="comment" id="comment" placeholder="* Comments..."></textarea>
<div class="error center" id="err-comment">Please enter your comment.</div>
</div></div>
<div class="control-group">
<div class="controls">
<button id="send-mail" class="message-btn">Send message</button>
</div></div></form>

,这是使用的mail.php代码:

include 'functions.php';

if (!empty($_POST)) {

$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);

//your email adress
$emailTo = "myemail@gmail.com"; //"myemail@gmail.com";

//from email adress
$emailFrom = "myemail@gmail.com"; //"myemail@gmail.com";

//email subject
$emailSubject = "Mail from MyEmail";

$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if ($name == "")
$data['success'] = false;

if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;

if ($comment == "")
$data['success'] = false;

if ($data['success'] == true) {

$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;
echo json_encode($data);
}
}

我真的被困在这一点上,这是我离开的唯一问题,希望有人可以帮助指出我做错了什么。

此致

圣拉斐尔

3 个答案:

答案 0 :(得分:1)

为了form发送POST个请求,您需要通过添加method属性来指定它:

<form id="contact-form" action="php/mail.php" method="post">

答案 1 :(得分:0)

你的php邮件脚本是否放在cgi目录中?这是我的邮件脚本:

       <?php $name = trim(strip_tags($_POST['name']));
   $email = trim(strip_tags($_POST['email']));
   $message = htmlentities($_POST['message']);
   $subject = "Some subject";
   $to = 'info@xxx.de';
   $body = <<<HTML 
$message 
HTML;

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";

   // send the email
   mail($to, $subject, $body, $headers);

   // redirect afterwords, if needed
   header('Location: ../contact/thx.html');?>

它放在cgi目录中。

答案 2 :(得分:0)

经过CodeGoodie的大量研究和帮助,我认为归咎于托管。我问过如何检查服务器日志以检测错误,他们只是回复我需要升级才能使用该功能(尽管它应该是该功能的一部分)。感谢所有帮助人员。我确实学到了很多东西:))