【问题标题】:Can't find whats wrong in my php for contact form在我的联系表单的 php 中找不到什么问题
【发布时间】:2016-01-09 19:12:30
【问题描述】:

我的联系表单中的 php 似乎无法正常工作。我得到一个 " 请更正以下错误:

写下你的信息 点击后退按钮,然后重试”如果有经验的人可以分享一些建议,我将非常感激。谢谢!

<?php
/* Set e-mail recipient */
$myemail = "myemail@com.com";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$phone = check_input($_POST['phone'], "Enter phone number");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "

Name: $name
E-mail: $email
Phone: $phone

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $phone, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>


 <div class="wrapper">  
    <div id="contact_form">
    <form name="form1" id="ff" method="post" action="form.php">

        <label>
        <span>Name*:</span>
        <input type="text" placeholder="Please enter your name" name="name" id="name" required autofocus>
        </label>

        <label>
        <span>Phone:</span>
        <input type="tel" placeholder="Please enter your phone" name="phone" id="phone">
        </label>



        <label>
        <span>Email*:</span>
        <input type="email" placeholder="youremail@gmail.com" name="email" id="email" required>
          </label>

           <label>
        <span>Message:</span>
       <textarea placeholder="message"></textarea>
        </label>


        <input class="sendButton" type="submit" name="Submit" value="Send">      
    </form>
    </div>
   </div>

【问题讨论】:

  • 请在发帖时删除机密信息,以供日后参考。
  • 很抱歉第一次来这里没有意识到。谢谢

标签: php html forms contact


【解决方案1】:

您正在寻找一个名为“消息”的值:

$_POST['message']

但您的表单中没有名为“消息”的表单元素。

给你的textarea添加一个名字:

<textarea name="message" placeholder="message"></textarea>

【讨论】:

  • 当然!谢谢,我以为消息有一个 ID,但它只是占位符。感谢您的快速响应!
  • 不幸的是,这不起作用!同样的错误信息:(你在php中还能看到我做错了什么吗?
猜你喜欢
  • 2011-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多