View Full Version : Premature end of script headers: newsletter.php

11-26-2010, 09:08 PM
I am completely stuck. I have managed to create and make most of my site work well for me, but every time I try and send out a newsletter from my site - I get the dreaded Premature End of Script error.

It refers to newsletter.php, so here is the coding for that page:


$q1 = "select * from class_members";
$r1 = mysql_query($q1) or die(mysql_error());

while($a1 = mysql_fetch_array($r1))
$to = $a1[email];
$subject = $_POST[sub];
$message = $_POST[MyMessage];

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: PHP/" . phpversion()."\n";

mail($to, $subject, $message, $headers);


$error = "$i messages was sent";

//get the number of registered members
$q1 = "select count(*) from class_members";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

if($a1[0] == 0)
echo "<br><br><center>There are no registered members, yet!</center>";


function CheckMail() {

alert('Enter the newsletter subject line, please!');
return false;

alert('Enter the newsletter text, please!');
return false;


<form method=post onsubmit="return CheckMail();" name=f1>
<table align=center width=500>


<td align=right>Subject:</td>
<td><input type=text name=sub size=36></td>

<td align=right valign=top>Message:</td>
<td><textarea name=MyMessage rows=10 cols=35></textarea></td>

<td><input type=submit name=s1 value="Send" class="sub1"></td>




Any help will be greatly appreciated!!!!

Thanks in advance!!!

11-26-2010, 11:32 PM
Hi, in the future could you please wrap your code in
tags? It preserves the formatting so its easier to read.

There are minor problems here that I can see, but nothing jumps out as fatal. Arrays when string indexed should be accessed with $myArray['mykey'] (notice the quotations). When in double quotes, you must use complex expansion:

$headers .= "From: {$_SERVER['HTTP_HOST']} <{$aset['ContactEmail']}>\n";

Note as well that your header's in an email should end with \r\n (make sure these are double quoted or they will not parse as the intended line feeds), unless your host rejects it (nowadays this shouldn't be a problem). <? should really be <?php for maximum compatibility (<? is a short_tag directive that can be disabled, and actually causes little 'issues' in the case of XML, which is why I wish it didn't exist at all >.<).

What is the actual error you are getting? Also, have you tried connecting to all of the included files directly to ensure that none of these are killing the process?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum