Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A spreadsite script problem
Old 05-10-2005, 06:59 AM A spreadsite script problem
Novice Talker

Posts: 6
Trades: 0
I'm using a spreadsite script on my site but when I send the email testing it he gives me an "headers already sent error" but sends me the email even so ... How can I get the script to send the user to a thanks.htm page?

Here's the spreadsite.php I would appreciate if anyone could give me an hand here

PHP Code:
<!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">
<head>
  <title>Penaf Spread site!</title>
</head>
<body>
<?php

//Configuration:

// number of friend's emails feilds to put on the page
$numberfriends "5";

// subject of the email
$subject "[This is not SPAM] A friend recommendation";

// Message sent in the email
$message "Just found this website and it's really cool! It has all kind of stuff an Webmaster can need or want!";

// The url to redirect user to once they click submit
$endurl "http://www.wise-designs.com/thanks.htm";

//Do not change bellow this line unless you know what you are doing!

if($submitform) {

$num=0;
while(
$num $numberfriends) {
$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 .= "You must enter your name!<BR>";
}
if(!
ereg("@",$email)) { $error .= "Invalid Email Address<BR>"; }
if(!
ereg("\.",$email)) { $error .= "Invalid Email Address<BR>"; }

if(
$error) {
?>
<p></p>
<center><table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%" bgcolor="#004080">
    <table width="394" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <td width="26%" bgcolor="#004080"><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>
<p><center>&nbsp;</center></p>
</body></html>
<?php
exit();
}


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

$message

-
$name

---------------------------------
http://www.wise-designs.com

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

}

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

} else {

$num=0;
while(
$num $numberfriends) {
$num++;
$friendboxes .= " <TR>
        <td width=\"49%\">
        <font color=\"#000000\" size=\"-1\" face=\"Verdana\">
$num</font></td>
        <td width=\"26%\"><input name=\"fname
$num\" type=\"text\" size=\"25\"></td>
        <td width=\"25%\"><input name=\"femail
$num\" type=\"text\" size=\"25\"></td> 
      </tr>"
;
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><p></p>
<center><table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%">
    <table width="394" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <td width="49%"></td>      
        <td width="26%"><font color="#000000" size="-1" face="Verdana">Your name</font></td>
        <td width="25%"><font color="#000000" size="-1" face="Verdana">Your E-mail</font></td>
      </tr>
      <tr>
        <td width="49%" valign="middle"></td>    
        <td width="26%"><center><input name="name" type="text" size="25" /></center></td>
        <td width="25%"><center><input name="email" type="text" size="25" /></center></td>
      </tr>
    </table></td>
  </tr>
</table></center>
<center><table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%">
    <table width="394" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <td width="49%"></td>
        <td width="26%"><font color="#000000" size="-1" face="Verdana">Friends name</font></td>
        <td width="25%"><font color="#000000" size="-1" face="Verdana">Friends email</font></td> 
      </tr><?php echo $friendboxes?>
            <tr>
        <td width="49%" valign="middle"></td>    
        <td width="26%"><p><input name="submitform" type="submit" value="Submit" /></p></td>
        <td width="25%"><p><input type="reset" name="Reset" value="Reset" /></form></p></td> 
      </tr></table></td>  
  </tr>
</table></center></P>
</body></html>
<?php
exit();
}
?>

Last edited by Penaf; 05-10-2005 at 11:11 AM..
Penaf is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-16-2005, 06:20 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
where do you want your thank you page to be ??
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 05-16-2005, 08:02 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
ROFL! "[This Is Not Spam]", good one.
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 05-16-2005, 09:34 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
ignore the last two irrelavent posts. You've already sent the headers because you've placed HTML content at the top of the page (before the <?PHP tags). It's giving you this error because you're then telling PHP to print more headers (directing them to the thanks page i think?) and PHP can't because you've already output to the browser.

So check this edited script out:
PHP Code:
<?php 

//Configuration: 

// number of friend's emails feilds to put on the page 
$numberfriends "5"

// subject of the email 
$subject "[This is not SPAM] A friend recommendation"

// Message sent in the email 
$message "Just found this website and it's really cool! It has all kind of stuff an Webmaster can need or want!"

// The url to redirect user to once they click submit 
$endurl "http://www.wise-designs.com/thanks.htm"

//Do not change bellow this line unless you know what you are doing! 

if($submitform) { 

$num=0
while(
$num $numberfriends) { 
$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 .= "You must enter your name!<BR>"

if(!
ereg("@",$email)) { $error .= "Invalid Email Address<BR>"; } 
if(!
ereg("\.",$email)) { $error .= "Invalid Email Address<BR>"; } 

if(
$error) { 
echo(
'
<!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"> 
<head> 
  <title>Penaf Spread site!</title> 
</head> 
<body> 
<p></p> 
<center><table border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td width="100%" bgcolor="#004080"> 
    <table width="394" border="0" cellspacing="1" cellpadding="2"> 
      <tr> 
        <td width="26%" bgcolor="#004080"><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">' 
$error '></font></td> 
      </tr> 
    </table></td> 
  </tr> 
</table></center> 
<p><center>&nbsp;</center></p> 
</body></html> 
'
);
exit(); 



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

$message 

-
$name 

--------------------------------- 
http://www.wise-designs.com 

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




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

} else { 

$num=0
while(
$num $numberfriends) { 
$num++; 
$friendboxes .= " <TR> 
        <td width=\"49%\"> 
        <font color=\"#000000\" size=\"-1\" face=\"Verdana\">
$num</font></td> 
        <td width=\"26%\"><input name=\"fname
$num\" type=\"text\" size=\"25\"></td> 
        <td width=\"25%\"><input name=\"femail
$num\" type=\"text\" size=\"25\"></td> 
      </tr>"


?>
<!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"> 
<head> 
  <title>Penaf Spread site!</title> 
</head> 
<body> 
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><p></p> 
<center><table border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td width="100%"> 
    <table width="394" border="0" cellspacing="1" cellpadding="2"> 
      <tr> 
        <td width="49%"></td>       
        <td width="26%"><font color="#000000" size="-1" face="Verdana">Your name</font></td> 
        <td width="25%"><font color="#000000" size="-1" face="Verdana">Your E-mail</font></td> 
      </tr> 
      <tr> 
        <td width="49%" valign="middle"></td>     
        <td width="26%"><center><input name="name" type="text" size="25" /></center></td> 
        <td width="25%"><center><input name="email" type="text" size="25" /></center></td> 
      </tr> 
    </table></td> 
  </tr> 
</table></center> 
<center><table border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td width="100%"> 
    <table width="394" border="0" cellspacing="1" cellpadding="2"> 
      <tr> 
        <td width="49%"></td> 
        <td width="26%"><font color="#000000" size="-1" face="Verdana">Friends name</font></td> 
        <td width="25%"><font color="#000000" size="-1" face="Verdana">Friends email</font></td> 
      </tr><?php echo $friendboxes?> 
            <tr> 
        <td width="49%" valign="middle"></td>     
        <td width="26%"><p><input name="submitform" type="submit" value="Submit" /></p></td> 
        <td width="25%"><p><input type="reset" name="Reset" value="Reset" /></form></p></td> 
      </tr></table></td>   
  </tr> 
</table></center></P> 
</body></html> 
<?php 
exit(); 

?>
There you go, that should work, all i've done is moved the HTML from the top of your page to where they should be anyway. Remember that the header() can only be used before ANY output to browser.

Also, a common mistake can simply be a space before the first <?PHP tag (a painful mistake i made a while ago)

Check back to tell us the results
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A spreadsite script problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52747 seconds with 12 queries