【发布时间】:2010-06-17 14:11:15
【问题描述】:
尽管遵循了我可以在网上找到的所有建议,但我还是遇到了标题位置问题。邮件程序脚本发送电子邮件,但我收到与第 29 行相关的“标头已发送”错误,即 {header("Location: $thanksURL");} 并且没有重定向到确认页面。如果我将标头位置代码替换为打印确认消息的指令,它会起作用,因此服务器不喜欢标头位置代码。
代码如下:
<?php
ob_start();
$to = "msheath@btinternet.com" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Request for Library Document";
$thanksURL = "http://www.postalhistory.org.uk/newsite/php/thankyou.php"; //confirmation page
$fields = array();
$fields{"name"} = "Name";
$fields{"address"} = "Address";
$fields{"email"} = "Email";
$fields{"tel"} = "Telephone No";
$fields{"author1"} = "First Author";
$fields{"title1"} = "First Title";
$fields{"author2"} = "Second Author";
$fields{"title2"} = "Second Title";
$body = "I would like to borrow the undermentioned book(s) from the PHS Library:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: The Librarian, Postal History Society";
$subject2 = "Thank you for contacting the Postal History Society";
$autoreply = "Thank you for your request. Somebody will get back to you as soon as possible, usually within 48 hours.";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header("Location: $thanksURL");}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
ob_end_flush()
?>
去http://www.postalhistory.org.uk/newsite/php/library.php自己试试吧。
谁能指出哪里出了问题?
迈克
【问题讨论】:
-
来自我的两个字:错误的代码格式
-
错误信息应该被完整地复制。您可能不知道,但通常错误消息包含帮助您修复它的信息。