PDA

View Full Version : error message when recommending a friend


comicw
10-30-2002, 11:12 PM
Hi,

When I tried out my php recommend a friend script (it's online), I got the following error message:

Warning: Cannot add header information - headers already sent by (output started at /home/broken/public_html/tellfriend.php:5) in /home/broken/public_html/tellfriend.php on line 110

How do I solve this?

wabirdman
10-31-2002, 01:30 AM
Any chance of posting the code??

wabirdman

comicw
10-31-2002, 07:26 AM
<HTML>
<HEAD>
<TITLE>Recommend a friend</TITLE>

<style type=text/css>
Body {scrollbar-3dlight-color : #AAAAB9; scrollbar-arrow-color : #FFB336; scrollbar-base-color : #AAAAB9;
scrollbar-darkshadow-color : #AAAAB9; scrollbar-face-color : #52525F; scrollbar-highlight-color : #52525F;
scrollbar-shadow-color : #52525F; scrollbar-track-color : #AAAB9}
</style>

</HEAD>
<BODY background="images/backg40.jpg">

<?php




$tellnumber = "3";


$subject = "Check out Broken Frontier!";


$message = "I found a great site about comics! Check out www.brokenfrontier.com for the latest news, reviews and interviews. You can also post your thoughts on the message board.";


$thankyouurl = "http://www.brokenfrontier.com";






if($submitform) {

$num=0;
while($num < $tellnumber) {
$num++;
$temail = "femail"."$num";
$tname = "fname"."$num";

if($$tname OR $$temail) {
if(!$$tname) {
$error .= "Missing Friends Name, Friend $num<BR>";
}
if(!$$temail) {
$error .= "Missing Friends Email, Friend $num<BR>";
}

}
if($$temail) {
if(!ereg("@",$$temail)) { $error .= "Invalid Email Address, Friend $num<BR>"; }
if(!ereg("\.",$$temail)) { $error .= "Invalid Email Address, Friend $num<BR>"; }
}
}
if(!$tname) {
$error .= "Missing your name<BR>";
}
if(!ereg("@",$email)) { $error .= "Invalid Email Address<BR>"; }
if(!ereg("\.",$email)) { $error .= "Invalid Email Address<BR>"; }

if($error) {
?>
<P><CENTER><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#DC5502">
<TABLE WIDTH="394" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD WIDTH="26%" BGCOLOR="#DC5502">
<B><FONT COLOR="#ffffff" SIZE="-1" FACE="Verdana">Error</FONT></B></TD>
</TR>
<TR>
<TD WIDTH="26%" BGCOLOR="#ffffff">
<FONT COLOR="#000000" SIZE="-1" FACE="Verdana"><?php echo $error; ?></FONT></TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></CENTER>
</BODY></HTML>
<?php
exit();
}


$num=0;
while($num < $tellnumber) {
$num++;
$temail = "femail"."$num";
$tname = "fname"."$num";
$then = $$tname;
if($$temail AND $$tname) {
mail($$temail,"$subject","
$then,

$message

Regards,
$name



","From: $name <$email>");
}

}

header("Location: $thankyouurl");
exit();

} else {

$num=0;
while($num < $tellnumber) {
$num++;
$theboxes .= " <TR>
<TD WIDTH=\"49%\" BGCOLOR=\"#DC5502\">
<P><CENTER><B><FONT COLOR=\"#FFB336\" SIZE=\"-1\" FACE=\"Verdana\">$num</FONT></B></CENTER></TD>
<TD WIDTH=\"26%\" BGCOLOR=\"#DC5502\">
<P><CENTER><INPUT NAME=\"fname$num\" TYPE=\"text\" SIZE=\"25\"></CENTER></TD>
<TD WIDTH=\"25%\" BGCOLOR=\"#DC5502\">
<INPUT NAME=\"femail$num\" TYPE=\"text\" SIZE=\"25\">
</TD>
</TR>";
}


?>
<P><CENTER><FONT FACE="Verdana" color="#DC5502" size="2"><B>Tell your friends about Broken Frontier!</B></FONT></CENTER></P>
<FORM ACTION="tellfriend.php" METHOD="POST"><P><CENTER><TABLE BORDER="0" CELLSPACING="0"
CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#DC5502">
<TABLE WIDTH="394" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD WIDTH="26%" BGCOLOR="#DC5502">
<P><CENTER><B><FONT COLOR="#FFB336" SIZE="-1" FACE="Verdana">Your name</FONT></B></CENTER></TD>
<TD WIDTH="26%">
<P><CENTER><B><FONT COLOR="#FFB336" SIZE="-1" FACE="Verdana">Your e-mail</FONT></B></CENTER></TD>
</TR>
<TR>
<TD WIDTH="26%" BGCOLOR="#DC5502">
<P><CENTER><INPUT NAME="name" TYPE="text" SIZE="25"></CENTER></TD>
<TD WIDTH="25%" BGCOLOR="#DC5502">
<INPUT NAME="email" TYPE="text" SIZE="25">
</TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></CENTER></P><P><CENTER><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#DC5502">
<TABLE WIDTH="394" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD WIDTH="49%" BGCOLOR="#DC5502"></TD>
<TD WIDTH="26%" BGCOLOR="#DC5502">
<P><CENTER><B><FONT COLOR="#FFB336" SIZE="-1" FACE="Verdana">Friends name</FONT></B></CENTER></TD>
<TD WIDTH="25%">
<P><CENTER><B><FONT COLOR="#FFB336" SIZE="-1" FACE="Verdana">Friends e-mail</FONT></B></CENTER></TD>
</TR><?php echo $theboxes; ?></TABLE></TD>
</TR>
</TABLE></CENTER></P>
<P><CENTER><INPUT NAME="submitform" TYPE="submit" VALUE="Submit"></CENTER></FORM>
</BODY></HTML>
<?php
exit();

}

?>

comicw
10-31-2002, 07:31 AM
well, I kinda fixed it by just leaving the "header" and "$thankyouurl" lines out, but now I just get a blank page when I've submitted the form. Is there a way to put a message on that blank page?

Can I implement that php part into my general layout page? If so, how should I do that?

Thanks!

Galdo
10-31-2002, 10:16 AM
You could either replace the header bit with some text or whatever you want to show the person, or you could use:

<META http-equiv=refresh content=0;URL=<?=$thankyouurl?>>

comicw
10-31-2002, 07:37 PM
Thanks! One more thing! Is it possible to insert something that sends me a copy of the mails that are sent to friends (without that being visible to the users of course)...?

Nightfire
10-31-2002, 08:13 PM
if($$temail AND $$tname) {
mail($$temail,"$subject","
$then,

$message

Regards,
$name



","From: $name <$email>");

// email to yourself
$youremail = "You@yourdomain.com";
$yoursubject = "$name as recommended a friend";
$yourmessage = "$name has just recommended a friend!";
$reply = "From: $youremail";
mail($youremail,$yoursubject,$yourmessage,$reply);

}

comicw
11-01-2002, 08:08 AM
I've tried it out, but I need this bit as well: the e-mail of the sender and the friend have to be visible to me too.

Thanks!

Nightfire
11-01-2002, 01:20 PM
// email to yourself
$youremail = "You@yourdomain.com";
$yoursubject = "$name as recommended a friend";
$yourmessage = "$name has just recommended a friend!
Friends email: $temail
Senders email: $email
Senders name: $name";
$reply = "From: $youremail";
mail($youremail,$yoursubject,$yourmessage,$reply);

comicw
11-01-2002, 06:57 PM
Nightfire, thanks for all the help!
However... one adjustment has to be made: I don't get to see the actual e-mail of the friends, only the messages
Friends e-mail: femail1
etc.

How can this be fixed?

Nightfire
11-01-2002, 07:02 PM
$yourmessage = "$name has just recommended a friend!
Friends email: $temail
Senders email: $email
Senders name: $name
Message sent: $message";