Error parsing variables via mail.php page..??

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

User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I posted the code as a full example.

I'm guessing you're either not called session_start() before you dump the $_SESSION array or you are setting the stuff to normal variables (eg. $name) and thinking it will work. Anything you want to store in a session you must assign to a key in the $_SESSION array.
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

Right, i have sorted it out, slightly..

I am passing the fields via hidden fields.

now i go from the 2nd page, and pass to the mail.php then redirect to the confirm page.

the mail.php is passing the variable to my email client, but the confirm page is blank and doing the session test the fields all come up blank.

you can check this out on My Website

any ideas?
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

This is my mail.php page, everything is passed to this page, and the email is sent brilliantly, now on the previous page, in the form, i set my redirect to "page6.php" and it does redirect to that page, but none of the variables are passed.!!!

It must be my mail.php page not passing to the redirect page, but why not??

I just cant see it..

Any ideas?

Code: Select all

<?
session_start(); 

$_SESSION['name'] = $_POST['name']; 
$_SESSION['address'] = $_POST['address'];
$_SESSION['address2'] = $_POST['address2']; 
$_SESSION['town'] = $_POST['town'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['postcode'] = $_POST['postcode'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['hear'] = $_POST['hear'];
$_SESSION['recommend'] = $_POST['recommend'];
$_SESSION['more'] = $_POST['more'];
$_SESSION['payment'] = $_POST['payment'];

$name = $_SESSION['name'];
$address = $_SESSION['address'];
$address2 = $_SESSION['address2'];
$town = $_SESSION['town'];
$county = $_SESSION['county'];
$postcode = $_SESSION['postcode'];
$phone = $_SESSION['phone'];
$hear = $_SESSION['hear'];
$recommend = $_SESSION['recommend'];
$more = $_SESSION['more'];
$amount = $_SESSION['payment'];

$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['account'] = $_POST['account'];

$username = $_SESSION['username'];
$password = $_SESSION['password'];
$account = $_SESSION['account'];


if ($_POST[recipient] && $_POST[subject] && $_POST[redirect]) {
  
  if ($_POST[required]) {
    $rfields = explode (",",$_POST[required]);
	foreach ($rfields as $check) {
	  if (!$_POST[$check]) {
	    header("Location: ".$_POST[errorpage]);
		exit(); 
	  }
	} 
  }
  
  if ($_POST[autoresponse] && $_POST[email]) {
    $html = file_get_contents($_POST[autoresponse]) or die("<b><font color=\"#ff0000\">Not a valid autoresponse page...</font><b>");
	if ($html) {
	  $tit_start = strpos($html,"<title>")+7;
	  $tit_end = strpos($html,"</title>")-$tit_start;
	  $mailsubject = $html;
	  $mailsubject = substr($mailsubject, $tit_start, $tit_end);
	  mail($_POST[email], $mailsubject, $html, "From: $_POST[autoresponsefrom]<$_POST[recipient]>\r\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1");
	}
  }
  else if (!$_POST[email]) {
    echo "<b><font color=\"#ff0000\">Email field required when using autoresponse mail...</font></b>";
    exit();
  }
  
  $ndata = array("recipient","subject","required","errorpage","redirect","autoresponse","autoresponsefrom");
  
  $postfields = $_REQUEST;
  
  foreach ($postfields as $k => $v) {
    if (in_array($k,$ndata)) unset($postfields[$k]);
	else $msg .= $k.": ".$v."\n";
  }
  
  mail($_POST[recipient],$_POST[subject],$msg,"From: $_POST[email]\r\n"."Reply-To: $_POST[email]\r\n");
  header("Location: ".$_POST[redirect]);
}
else echo "<b><font color=\"#ff0000\">Recipient, subject or redirect field is missing...</font></b>";
?>
Post Reply