PDA

View Full Version : PHP Mailer re-direct issue


kona72
04-25-2007, 01:06 AM
Hey All,

I have been using phpmailer to send a simple form and running into a problem. When I go to the page /tell_a_friend.php it automatically re-directs me to the thank you page /thankyou.php with out giving me the opportunity to fill the form.. not good... I have looked it over for 2 days now and still cannot come up with what i am doing wrong?? Can someone please lend a hand?

Here is the tell_a_friend.php page... it's here if you want to see what I mean...

http://www.krasemannart.com/tell_a_friend.php



<?php
include("class.phpmailer.php");

{
$contents ="Hello $_REQUEST[frname],<br>I found this site I thought you would enjoy <a href='http://www.krasemannart.com/'>Krasemannart.com</a> <br />You should go and check it out. ".$_REQUEST[message]." <br>Sincerely,<br>$_REQUEST[yname]";

$mail = new PHPMailer;
$mail->mailer ="sendmail";
$mail->Subject = $_REQUEST[yname].' wants you to see this website Krasemannart.com' ;
$mail->From ="$_REQUEST[yemail]" ;
$mail->FromName ="$_REQUEST[yname]";
$mail->Body = stripslashes($contents);
$mail->AltBody = stripslashes($contents);
$mail->IsHTML(true);
$mail->AddAddress($_REQUEST[fremail],$_REQUEST[frname]);
$mail->send();

header("location:thankyou.php");
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>.:: Krasemann Art ::.</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper"> <!--Wrapper Begin-->
<div id="header"></div><!--header Begin and end-->
<div id="content"><!--content Begin-->
<div id="navigation">
<?php include("nav.php"); ?>
</div>
<div id="content p"><!--contentP Begin--><p>&nbsp;</p>
<p>Tell a friend about Stephen's Website! </p>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER[PHP_SELF] ?>">
<p align="center"></p>
<p>
<input name="yname" type="text" id="yname" />
Your Name</p>
<p>
<input name="yemail" type="text" id="yemail" />
Your Email Address </p>
<p>
<input name="frname" type="text" id="frname" />
Your Friend's Name </p>
<p>
<input name="fremail" type="text" id="fremail" />
Your Friend's Email Address </p>
<p>Your Message (Optional) </p>
<p>
<textarea name="textarea" cols="50" rows="5"></textarea>
</p>
<p>
<input type="submit" name="sendmail" src="images/send-email.gif" value="Sendmail">
</p>
</form>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall">&nbsp;</p>
<p class="subheadingsmall"><br />
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<!--contentP Begin-->
</div><!--content End-->
<div id="footer">&nbsp;<a href="http://www.trafick.net" target="_blank"><img src="images/krasemann_10.jpg" width="780" height="46" border="0" /></a></div>
<!--footer Begin and End-->
</div><!--Wrapper End-->
</body>
</html>

davidj
04-25-2007, 05:41 AM
where is your IF Condition

kona72
04-25-2007, 01:26 PM
oh yeah....


if ( $dough_head_who_doesnt_know_php == "me" )
{
echo "why are you even trying this?<br />";
}
header: ("location:http://www.dreamweaverclub.com");



Is this at least the right structure??

davidj
04-25-2007, 01:42 PM
except replace the variable

$dough_head_who_doesnt_know_php

with

$not_quite_a_dough_head_but_qualifies_as_a_Part_ti me_Helmet

that variable will work

kona72
04-25-2007, 01:54 PM
HAHAHAHAHA

So i understand the structure but still am having a time with the language...

I will do some more research and then post my results....

davidj
04-25-2007, 01:57 PM
just add a condition to what you have already


if(isset($_POST['mail'])) //<< added condition which could be a hidden field called mail with a value of 1.
{
$contents ="Hello $_REQUEST[frname],<br>I found this site I thought you would enjoy <a href='http://www.krasemannart.com/'>Krasemannart.com</a> <br />You should go and check it out. ".$_REQUEST[message]." <br>Sincerely,<br>$_REQUEST[yname]";

$mail = new PHPMailer;
$mail->mailer ="sendmail";
$mail->Subject = $_REQUEST[yname].' wants you to see this website Krasemannart.com' ;
$mail->From ="$_REQUEST[yemail]" ;
$mail->FromName ="$_REQUEST[yname]";
$mail->Body = stripslashes($contents);
$mail->AltBody = stripslashes($contents);
$mail->IsHTML(true);
$mail->AddAddress($_REQUEST[fremail],$_REQUEST[frname]);
$mail->send();

header("location:thankyou.php");
}

kona72
04-25-2007, 03:36 PM
Great... That works fantastic!
My issue is I don't understand why?


if(isset($_POST['mail']))


Where does the 1 in the hidden field come into play? it doesn't have to validate the 1? Probably a dumb question... but better that just pluggin in the code and accepting it that it works.. I want to understand why.

davidj
04-25-2007, 03:45 PM
nice one mate

i like people who want to understand

//************
My issue is I don't understand why?

you are passing a value. Thats it!

then checking if the variable is set with a value. Its a way to check if a button has been pressed.

it can be any value you want but i always use 1 because 6 months later when i revisit the script and see 456 as a value or 223 or 11abc or 999 i will be thinking WHAT THE HELL IS THAT ABOUT! so i just use 1. It keeps it simple

kona72
04-25-2007, 03:51 PM
AH... makes sense... so before the if(isset) command then the page automatically processed the form and went directly to the header(location... page... right? now that i have the hidden field it stops on the if statement until further user interaction? Am i following this correct?

Thanks DJ

davidj
04-25-2007, 05:14 PM
an IF statement is as follows

IF($condition == true){

do stuff here

}else{

do other stuff

}

or an ELSE IF

IF($condition == true && $newcondition2 == false){

do stuff here

}elseif($condition == true && $newcondition2 == true){

do other stuff

}


the IF condition has to be met which makes it true then anything inside the braces will be processed