simple sessions/header problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

simple sessions/header problem

Post by d3ad1ysp0rk »

mail.php:

Code: Select all

<?PHP
if($refresh=="yes" && un!="")
{
    session_start();
    $_SESSION['mailcontent'] = $mailcontent;
    $_SESSION['un'] = $un;
    $_SESSION['refresh'] = $refresh;
    header("location: mailfinish.php");
} ?>
<html>
<head>
<title>Email Page</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="<?PHP echo "$bgc"; ?>">
Email me without having to log into anything! Just fill out your message, and then your name or screen name and click submit! =)
<form name="mail" method="post" action="<?PHP echo "$PHP_SELF"; ?>">
<input type="textarea" name="mailcontent">
<input type="text" name="un" "size="25">
<input type="hidden" name="refresh" value="yes">
<input type="submit" name="submit" value="Send">
</form>
</body>
</html>

mailfinish.php:

Code: Select all

<html>
<body>
<?PHP
session_start();
if($mailcontent!="" && $un!="" && refresh=="yes")
{
mail("lppunkskater@hotmail.com", "Automated Scipt", "$mailcontent");
echo "Mail sent!";
}
else
{
echo "Error sending mail. IM LPpunkSkateR please.";
}
?>
</body>
</html>
I get this when I submit the form on mail.php:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/des404/public_html/mailfinish.php:3) in /home/des404/public_html/mailfinish.php on line 4
Error sending mail. IM LPpunkSkateR please.
Anyone?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

mail.php

Code: Select all

<?php
    ob_start();
    $un = $_POST&#1111;'un'];
    $refresh = $_POST&#1111;'refresh'];
    $mailcontent = $_POST&#1111;'mailcontent'];
    if((strcmp($refresh, 'yes') == 0) && isset($un)) &#123;
        $dom = $_SERVER&#1111;'SERVER_NAME'];
        $self = $_SERVER&#1111;'PHP_SELF'];
        if(!headers_sent()) &#123;
            session_start();
            $_SESSION&#1111;'un'] = $un;
            $_SESSION&#1111;'refresh'] = $refresh;
            $_SESSION&#1111;'mailcontent'] = $mailcontent;
            session_write_close();
            header('Location: http://' . $dom . '/mailfinish.php');
            exit();
        &#125;
    &#125;
?>
<HTML> 
<HEAD> 
<TITLE>Email Page</TITLE> 
<LINK REL="stylesheet" HREF="style.css" TYPE="text/css"> 
</HEAD> 
<BODY BGCOLOR="<?=$bgc?>"> 
Email me without having to log into anything! Just fill out your message, and 
then your name or screen name and click submit! =) 
<FORM NAME="mail" METHOD="post" ACTION="<?=$self?>"> 
  <INPUT TYPE="textarea" NAME="mailcontent"> 
  <INPUT TYPE="text" NAME="un" "size="25"> 
  <INPUT TYPE="hidden" NAME="refresh" VALUE="yes"> 
  <INPUT TYPE="submit" NAME="submit" VALUE="Send"> 
</FORM> 
</BODY> 
</HTML> 
<?php
    ob_end_flush();
?>
mailfinish.php

Code: Select all

<?php
    ob_start();
?>
<HTML> 
<HEAD> 
<?php
    if(!headers_sent()) &#123;
        session_start();
        $un = $_SESSION&#1111;'un'];
        $refresh = $_SESSION&#1111;'refresh'];
        $mailcontent = $_SESSION&#1111;'mailcontent'];
        if(empty($mailcontent) || empty($un) || strcmp($refresh, 'yes') != 0) &#123;
            echo 'Error sending mail. IM LPpunkSkateR please';
        &#125; else &#123;
            mail('lppunkskater@hotmail.com', 'Automated Scipt', $mailcontent);
            echo 'Mail sent!';
        &#125;
        session_write_close();
    &#125;
?>
</BODY> 
</HTML>
<?php
    ob_end_flush();
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

I finished the script before checking back to this topic.
So here it is:

http://www.404-design.net/mail.php

I would change it, but I'm not sure what half the stuff you put is, and mine seems to be working fine.

mail.php

Code: Select all

<?PHP
if($refresh=="yes" && un!="")
{
    session_start();
    $_SESSION['mailcontent'] = $mailcontent;
    $_SESSION['un'] = $un;
    $_SESSION['refresh'] = $refresh;
    echo "<meta http-equiv="refresh" content="0;URL=mailfinish.php">";
} ?>
<html>
<head>
<title>Email Page</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body bgcolor="#000000">
<form name="mail" method="post" action="<?PHP echo "$PHP_SELF"; ?>">
<table width="380" cellspacing="0" cellpadding="0" border="0">
<tr><td colspan="2" valign="top">Email me without having to log into anything! <br>Just fill out your message, and then your name or screen name and click submit!</td></tr>
<tr>
<td valign="top" width="110">Name or SN: </td>
<td valign="top" width="270"><input type="text" name="un" size="15"></td>
</tr>
<tr>
<td valign="top" width="110">Email Content: </td>
<td valign="top" width="270"><textarea name="mailcontent" cols="50" rows="5"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="refresh" value="yes">&nbsp;</td>
<td valign="top" align="center"><input type="submit" name="submit" value="Send"></td>
</tr>
</table>
</form>
</body>
</html>
mailfinish.php

Code: Select all

<?PHP session_start(); ?>
<html>
<body>
<?PHP
if($mailcontent!="" && $un!="" && $refresh=="yes")
{
    mail('lppunkskater@hotmail.com', 'Automated Scipt', '$mailcontent');
    echo "Mail sent!";
}
else
{
    echo "Error sending mail. IM LPpunkSkateR please.";
}
?>
</body>
</html>

Thanks everyone. :)
Post Reply