【问题标题】:PHP Warning: Cannot modify header information - headers already sent by (output started at.......on line 29 [duplicate]PHP 警告:无法修改标头信息 - 标头已由(输出开始于.......第 29 行 [重复]
【发布时间】:2013-10-18 18:23:49
【问题描述】:

每次我尝试点击发送时都会出现此错误。 我在电子邮件中收到消息,但问题是它会将我带到错误页面,而不是带我到我指定的页面。

这是我的代码:

<?php 
$errors = '';
$myemail = 'info@cherry-ao.com';//<-----Put Your email address here.

if(empty($_POST['name'])  ||  empty($_POST['email']) || empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address";
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thank_you.html');
} 

echo nl2br($errors);
?>

没有空格! 我用 Hostgator 托管我的网站

【问题讨论】:

  • 您是否包含来自另一个可能已经发送标头的文件?

标签: php html sendmail html-email web-hosting


【解决方案1】:

如果你在屏幕上放了一些数据,你就不能写标题。

标题必须位于代码的顶部,然后才能输出给用户

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 2010-12-27
    • 2011-05-09
    • 1970-01-01
    相关资源
    最近更新 更多