Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Premature end of script headers: newsletter.php

    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:

    <?
    require_once("../conn.php");
    require_once("access.php");
    require_once("AdminNavigation.php");

    if(isset($_POST[s1]))
    {
    $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);

    $i++;
    }

    $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>";
    exit();
    }

    ?>

    <script>
    function CheckMail() {

    if(document.f1.sub.value=="")
    {
    alert('Enter the newsletter subject line, please!');
    document.f1.sub.focus();
    return false;
    }

    if(document.f1.MyMessage.value=="")
    {
    alert('Enter the newsletter text, please!');
    document.f1.MyMessage.focus();
    return false;
    }

    }
    </script>

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

    <tr>
    <td></td>
    <td><b>Newsletter</b><br><?=$error?></td>
    </tr>

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

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

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

    </table>

    </form>

    <?
    require_once("admin_footer.php");
    ?>

    Any help will be greatly appreciated!!!!

    Thanks in advance!!!
    Wendy

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Hi, in the future could you please wrap your code in [php][/php] 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:
    PHP Code:
    $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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •