Cannot modify header information
Jeg får denne fejl:Warning: Cannot modify header information - headers already sent by (output started at d:\web\TEST\YmAdmin\Send_mail_admin.php:163) in d:\web\TEST\YmAdmin\Send_mail_admin.php on line 181
Og jeg har prøvet at slette alle mellemrum men uden held: du kan se koden her da det er det sidste jeg mangler:
<?php
if (!empty($_GET)) {
extract($_GET);
} else if (!empty($HTTP_GET_VARS)) {
extract($HTTP_GET_VARS);
}
if (!empty($_POST)) {
extract($_POST);
} else if (!empty($HTTP_POST_VARS)) {
extract($HTTP_POST_VARS);
}
if (!isset($sub)){
include_once("head.php"); ?>
<table cellpadding="0" cellspacing="0" width="100%" class="bottomborder_top">
<tr>
<td><span class="TopText">Newsletter administration</span></td>
<td align="right"><center><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Departures admin</a> -
<SCRIPT TYPE="text/javascript">
<!--
var bl = new backlink();
bl.write();
//-->
</SCRIPT>
</center></td>
</tr>
</table>
<table cellpadding="2" cellspacing="2" border="0" width="100%">
<tr>
<td colspan="2">To send news letters you need to fill out the below form and press the send button. The newsletter will then be sent to all registered users at our foundation<br />
To see the resent newsletter you should check the inbox for newsletters from us</td>
</tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?sub=send" method="post">
<tr>
<th>Subject:</th><td><input name="subject_text" value="" size="63" /></td>
</tr>
<tr>
<th>Text:</th><td><textarea cols="48" rows="14" name="body_text"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Send newsletter" /></td>
</tr>
</form>
</table>
<?php include_once("footer.php");
}
if (isset ($_GET['sub']) && $sub == 'send'){
include_once ("auth.php");
if (!empty($_GET)) {
extract($_GET);
} else if (!empty($HTTP_GET_VARS)) {
extract($HTTP_GET_VARS);
}
if (!empty($_POST)) {
extract($_POST);
} else if (!empty($HTTP_POST_VARS)) {
extract($HTTP_POST_VARS);
}
class smtp_client {
var $connection;
var $server;
var $elog_fp;
var $log_file='log/smtp.log';
var $do_log=true;
// default constructor
function smtp_client($server='smtp.mail.dk') { //din udbyders smtp server
if (!$server) $this->server="localhost";
else $this->server=$server;
$this->connection = fsockopen($this->server, 25);
if ($this->connection <= 0) return 0;
$this->elog(fgets($this->connection, 1024));
$this->elog("HELO xyz\r\n", 1);
fputs($this->connection,"HELO xyz\r\n");
$this->elog(fgets($this->connection, 1024));
}
function email($from_mail, $to_mail, $to_name, $header, $subject, $body) {
if ($this->connection <= 0) return 0;
$this->elog("MAIL FROM:$from_mail", 1);
fputs($this->connection,"MAIL FROM:$from_mail\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("RCPT TO:$to_mail", 1);
fputs($this->connection, "RCPT TO:$to_mail\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("DATA", 1);
fputs($this->connection, "DATA\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("Subject: $subject", 1);
$this->elog("To: $to_name", 1);
fputs($this->connection,"Subject: $subject\r\n");
fputs($this->connection,"To: $to_name\r\n");
if ($header) {
$this->elog($header, 1);
fputs($this->connection, "$header\r\n");
}
$this->elog("", 1);
$this->elog($body, 1);
$this->elog(".", 1);
fputs($this->connection,"\r\n");
fputs($this->connection,"$body \r\n");
fputs($this->connection,".\r\n");
$this->elog(fgets($this->connection, 1024));
return 1;
}
function send() {
if ($this->connection) {
fputs($this->connection, "QUIT\r\n");
fclose($this->connection);
$this->connection=0;
}
}
function close() { $this->send(); }
function elog($text, $mode=0) {
if (!$this->do_log) return;
// open file
if (!$this->elog_fp) {
if (!($this->elog_fp=fopen($this->log_file, 'a'))) return;
fwrite($this->elog_fp, "\n-------------------------------------------\n");
fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "\n");
fwrite($this->elog_fp, "-------------------------------------------\n");
}
// write to log
if (!$mode) fwrite($this->elog_fp, " $text\n");
else fwrite($this->elog_fp, "$text\n");
}
}
include_once ("../Forum/cfig.php");
$res = mysql_query("SELECT Email, Realname FROM users WHERE NewsLetter ='1'") or die (mysql_error());
$from = "support@mail.com"; //din egen mail :-)
$header = "Content-type: text/plain; charset=ISO-8859-1";
$subject = $_REQUEST['subject_text'];
$body = $_REQUEST['body_text'];
$smtp = new smtp_client;
$smtp -> smtp_client();
while (list($Email, $Realname) = mysql_fetch_row($res)) {
$smtp->email("$from", "$Email", "$Realname", "$header", "$subject", "$body");
echo "Mail sent to $Email<br />";
}
$smtp->send();
mysql_close($db);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body leftmargin="0" topmargin="0">
Wait to be transfered back to the site.
</body>
</html>
<?php header("location: http://www.mysite.com/index.php");
exit;
} ?>
