Page 1 of 1

Session Variables

Posted: Tue Sep 25, 2007 2:25 am
by phpcoder
Hi,

I am losing values in session variables after the successful transaction. I am using securetrading for payement gateway. What I want when the user transaction is successfull then I want to send user a confirmation email, right know when I try to access is session variables, to get user email address, the session variable returns nothing. Also I am trying to send HTML email but when I display this the HTML tags does not works I thing I need some header please help me in sorting these two issues.
Thanks

Code: Select all

if ($settings->PaymentPortal=='securetrading' && isset($_POST['stresult'])) {
	include_once("inc/dbopen.php");
	$query='';
	$query=changefield($query,'PaymentStatus',$_POST['stresult']. '~'.$_POST['securityresponseaddress']. '~'.$_POST['securityresponsepostcode']. '~'.$_POST['securityresponsesecuritycode']. '~'.$_POST['stconfidence']. '~'.$_POST['securitymessage']);
	$query=changefield($query,'PaymentAuthorisation',str_replace('AUTH CODE:','',$_POST['stauthcode']));
	$query=changefield($query,'PaymentID',$_POST['streference']);
	$query=changefield($query,'PaymentSecurityKey',$_POST['timestamp']);
	$query = "UPDATE tblOrder ".$query." WHERE OrderID='".$_POST['orderref']."';";
	mysql_query($query);
	if (mysql_error()) {
		#echo $query.'<br />'.mysql_error();
	}
	DownDateProducts($_POST['orderref']);
	if ($_POST['stresult']=='1') {
		$errormessage="Thank you for your payment, your order has been confirmed by email...";
		
		
		
		
		##################################
		
		
				
		
		
	

	//*********************************************************************************************
	
	
		
	
		
			

	
	$body = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
			Dear '.$userID .',<br />

                                    <br />

                                    Thank you for your order.<br />

                                    <br />

                                    <strong>Please keep a copy of this e-mail for your records.</strong><br />

                                    <br />

                                    <table width="700" border="0" cellpadding="0" cellspacing="0" class="border-collapse-12px">

                                    <tr>

                                      <td><strong class="text">Details of your order:</strong><br />
                                        
                                        <br />
                                        
                                        <table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#B7CFEE" class="border-collapse-10px">
                                          
                                          <tr>
                                            
                                            <td bgcolor="#FF66CC"><strong>Product Description: </strong></td>
  
                                    <td width="70" align="center" bgcolor="#FF66CC"><strong>Qty</strong></td>
  
                                    
  
                                    <td width="70" align="center" bgcolor="#FF66CC"><strong>Total Price </strong></td>
                                    </tr>';
                                          
                                                                                
                                          foreach ($cart->items as $id => $item) { 
										  
                                          
                                          $body .= '<tr>
                                            
                                            <td>'.$item->name.'</td>
  
                        <td align="center">'.$item->qty.'</td>
  
                       
  
                        <td align="center">£'.number_format($item->extendedPrice(), 2,'.','').'</td>
  
              </tr>';
                                          
                                          }
                                          
                                          
                                          
                                          $body .= '          </table>
  
                                    <br>
                                        
                                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="border-collapse-12px">
                                          
                                          <tr>
                                            
                                            <td width="50%" valign="top"><strong>Your Delivery Details:</strong><br />
                                              
                                              <br />
                                              
                                              <table border="1" cellpadding="5" cellspacing="0" bordercolor="#B7CFEE" class="border-collapse-12px">
                                                
                                                <tr>
                                                  
                                                  <td width="207">'.$address.'</td>;
                                                    
                                                    
                                                    
  
                                    </tr>
                                                
                                              </table></td>
  
                                    <td width="50%" align="right" valign="top">
                                      
                                      <table border="1" align="right" cellpadding="5" cellspacing="0" bordercolor="#B7CFEE" class="border-collapse-10px">
                                        
                                        <tr>
                                          
                                          <td width="70" bgcolor="#FF66CC">Carriage:</td>
  
                                    <td width="70" align="center">£'.number_format($query, 2,'.','').'</td>
                                    </tr>
                                        
                                        <tr>
                                          
                                          <td bgcolor="#FF66CC"><strong>Grand Total: </strong></td>
  
                                    <td align="center"><strong>&pound;'.number_format($cart->getTotalPrice()+$query, 2,'.','').'</strong></td>
                                    </tr>
                                      </table></td>
  
                                    </tr>
                                          
                                        </table>
  
                                    <br></td>
                                    </tr>

                                    </table>

                                    </body>

                                    </html>';

	
	
	
	
	
	
	
	
	
	//***********************************************************************************************
	
	$to = $_SESSION['logged_user'];
	
	$from= "Orders@perfumeforpleasure.com";
$subject = "P4P Order Confirmation !";
if (mail($to, $subject, $body, $from)) {

 
 } else {
 }

Posted: Tue Sep 25, 2007 3:20 am
by N1gel
Are you using session_start() you will need to create or resume a session for the session variables to retain there values have a look at

session_start();

Sorry can't help with the HTML e-mail

Posted: Tue Sep 25, 2007 3:32 am
by aceconcepts
I would certainly check if you have started/resumed the session. You should place session_start() at the very top of you scripts.

Regarding the HTML tags, your mail() doesn't contain any headers that will allow HTML to display.

Use a search engine to find a tutorial on "PHP HTML email" scripts - there are lots out there and some of them are very educational.

Posted: Tue Sep 25, 2007 4:14 am
by phpcoder
aceconcepts wrote:I would certainly check if you have started/resumed the session. You should place session_start() at the very top of you scripts.

Regarding the HTML tags, your mail() doesn't contain any headers that will allow HTML to display.

Use a search engine to find a tutorial on "PHP HTML email" scripts - there are lots out there and some of them are very educational.
No it was not session issue it was my actual payemet gateway configuration which was creating problems. My configuration file suppose to send me all variables back so I can use them again. So I changed my configuration file now it is working fine. I am searching for HTML emails so hopefully it will be sorted soon. If any one can help me in sending HTNL emails then let me know.
Thanks

Posted: Tue Sep 25, 2007 4:27 am
by aceconcepts
Here you are - this script should work for you. Simply change the values specific to your own script:

Code: Select all

$to = "name@domain.com";
		$subject = "Subject here";
		$message="<html stuff here>";
		$from = "from@domain.com;
		//add From: header
		$headers = "From: " . $from. "\r\n";
		
		//specify MIME version 1.0
		$headers .= "MIME-Version: 1.0\r\n";
		
		//unique boundary
		$boundary = uniqid("HTMLDEMO");
		
		//tell e-mail client this e-mail contains//alternate versions
		$headers .= "Content-Type: multipart/alternative" .
		   "; boundary = $boundary\r\n\r\n";
		
		//message to people with clients who don't
		//understand MIME
		$headers .= "This is a MIME encoded message.\r\n\r\n";
		
		//plain text version of message
		$headers .= "--$boundary\r\n" .
		   "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
		   "Content-Transfer-Encoding: base64\r\n\r\n";
		$headers .= chunk_split(base64_encode("This is the plain text version!"));
		
		//HTML version of message
		$headers .= "--$boundary\r\n" .
		   "Content-Type: text/html; charset=ISO-8859-1\r\n" .
		   "Content-Transfer-Encoding: base64\r\n\r\n";
		$headers .= chunk_split(base64_encode($message)); 
		
		mail($to,$subject,$message,$headers,"-f $from");
Hope it works for you.