Jump to content

Would this cause a problem?


nick2price

Recommended Posts

Sorry. Just a quick question. I have the following

 

	foreach($_SESSION as $k => $sess){
    $message .= $k.": ".$sess."\n".$emailID."\n";
}
if(mail($to, $subject, $message)){
	header("Location: successfulPayment1.html");
}
else {
	echo "ERROR!";
}

} else {

echo "ERROR!";

}

Witout the mail function in an if statement, I received the session variables. With it in the if statement, I receive empty variables. Is the if statement interfering with the forelse loop? And is there a way I can do it like i am attempting, because I only want the header if the email was successful.

Link to comment
https://forums.phpfreaks.com/topic/206221-would-this-cause-a-problem/
Share on other sites

Is the if statement interfering with the forelse loop?

No

 

is there a way I can do it like i am attempting, because I only want the header if the email was successful.

1. There is no way to know if the email was recieved, only if it was managed to be sent.

2. The code you have provided here (minus the extra else statement at the bottom) is in working order. eg:

 

   foreach($_SESSION as $k => $sess){
       $message .= $k.": ".$sess."\n".$emailID."\n";
   }
   if(mail($to, $subject, $message)){
      header("Location: successfulPayment1.html");
   }
   else {
      echo "ERROR!";
   }

 

Should work as intended. (Assuming $emailID is already set before this code, and that Sessions variables do exist.)

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.