使用我的php代码时出现此错误。虽然我收到了电子邮件

时间:2013-08-20 16:33:46

标签: php html mysql

我想让php联系人在用户正确提交后重定向到感谢页面,但事实并非如此,所有这一切都是这个

警告:无法修改标头信息 - 已由()

发送的标头

这是我的thanks.html

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Thank you we will get back to you </title>
<meta content="php, contact, form, thinking" name="keywords">
<meta content="Great success!" name="description">

<style>
p {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}

h1 {
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: xx-large;
color: #3399FF;
}
body {
padding: 10px;
background-color: #F4F4F4;
}
</style>

</head>

<body>
<h1>&nbsp;</h1>
<h1>Thank You!</h1>
<p>We've received your request,  we will get back to you soon.</p>

</body>

</html>

这是我的php,名为mailer.php

<?php 

$name = $_POST['name'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $message = $_POST['message'];
    $from = 'From:you'; 
    $to = 'me@hotmail.com'; 
    $subject = 'Hello';
    $human = $_POST['human'];

    $body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";


if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';

            header("Location: thanks.html");

        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
    } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
    }
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }



}


 ?>

这是我的contact.html页面,只是表单部分。

<h1 class="contactcat">Contact us for </h1>


   <form action="mailer.php"  method="post">

      <label>Name</label>
    <input name="name" placeholder="Type Here">

    <label>Email</label>
    <input name="email" type="email" placeholder="Type Here">

    <label>Contact Number</label>
    <input name="number" type="text" placeholder="Type Here">

    <label>Message</label>
    <textarea name="message" placeholder="Type Here"></textarea>
    <br/>

    <label>What's 2+2 (type only the number)</label>
         <input name="human" type="number" placeholder="Type Here">
        <br/>

    <input id="submit" name="submit" type="submit" value="Submit">

</form>

1 个答案:

答案 0 :(得分:3)

echo '<p>Your message has been sent!</p>';

在尝试发送已经发送的标头之前,您有echoing个信息。在尝试发送headers之前,您无法向浏览器发送任何内容