联系表单提交时出错

时间:2014-01-05 23:13:36

标签: php html forms form-submit contact

大家好我有一个问题,我希望你们可以提供帮助,我在所有领域打字然后按下提交我只是“错误!”在我的屏幕上。

请参阅代码:

HTML

<h2 class="formhead">Contact Form</h2>
<br>
  <form class="form" action="mail.php" method="POST">

    <p class="name">
        <input type="text" name="name" id="name" placeholder="John Doe" />
        <label for="name">Name</label>
    </p>
<br>
    <p class="email">
        <input type="text" name="email" id="email" placeholder="mail@example.com" />
        <label for="email">Email</label>
    </p>
<br>
    <p class="number">
        <input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
        <label for="name">Contact Number</label>
    </p>
<br>
    <p class="web">
        <input type="text" name="web" id="web" placeholder="www.example.co.uk" />
        <label for="name">Website</label>
    </p>
<br>
    <p class="message">
        <textarea name="message" id="message" placeholder="Write something to us" /> </textarea>
    </p>
<br>
    <p class="submit">
        <input type="submit" value="Send"/>
    </p>
  </form>

PHP

<?php $name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$website = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries@c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

非常感谢任何帮助!

由于

萨姆

2 个答案:

答案 0 :(得分:3)

您的脚本始终报告'Error!',因为mail()功能始终失败。那是因为你在php文件中使用的某些索引与表单中的输入名称不匹配:

更改这些:

$website = $_POST['website'];

为:

$website = $_POST['web'];

或者在表单中更改。

此外,您还必须为消息textarea指定名称:

<textarea name="message" id="message" placeholder="Write something to us" />

如果无法连接到邮件服务器,则可能会再次失败。如果SMTP已禁用,可能就是这种情况。

答案 1 :(得分:0)

根据我的评论,这是一个更好的死亡陈述的例子:

<?
$your_function or die("Error! a") // Just replace the letter a with anything. It serves as a simple link to your function that only you know.  so you can go back and check it