Link to home
Start Free TrialLog in
Avatar of digigirl1124
digigirl1124Flag for United States of America

asked on

PHP mail() showing same email address over and over, instead of new registrant. Is this problem with my $_SESSION variables?

PHP mail() showing same email address over and over, instead of new registrant.  Is this problem with my $_SESSION variables?

I set up a response email to each new dealer who registers on our site and it now works great showing the variable names inside the email body!!! (thanks to angellll at EE!)
However, now, when testing it, Even though I use different fake email addresses ((with a cc: to my email address, so that I can see what the response looks like.)) it is giving me the SAME email address over and over and over in the body of the email response.

ie:  Once it started showing the email and password in the body of the email,  I realized that it is showing the same one over and over, no matter who i use as a login or password.  It looks like it is stuck in a time warp!! lol...

so does this have something to do with the $_SESSION variables or is it in my code?? or could it be that I am using a PC with IE and Mozilla to test, and can't completely clear out the cookies???  not sure why it would take the variable from a previous registered user, instead of the current registering user??

THANK YOU IN ADVANCE!!!
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

well, without seeing the relevant part of the code of the form that the new registrations entry form submits, and the relevant part of the page that the forms is getting submitted to.
and please, don't just throw all the code ... :)
Avatar of digigirl1124

ASKER

sorry, i wasn't sure what you need... below are snippets

//BELOW IS THE CODE SNIPPET FOR THE FIRST REGISTRATION PAGE --- ASKING USER TO SET UP A USER ID (email address) and PASSWORD ......... THE CODE WORKS WELL INSERTING INTO THE DATABASE

$addNewDealer = @mysql_query("INSERT INTO dealer_user (dealer_id, d_email, d_pass, signup_date) VALUES (NULL, '".$_POST['d_email']."', '".$_POST['d_pass']."', now())")
        or die (mysql_error());
            //$add_member = mysql_query($insert);
        if (!addNewDealer)
        {
        echo 'There has been an database error. Please contact the webmaster.' . mysql_error();
        }
        else
        {

// CALLING THE CURRENT AUTO INCRE ROW NUMBER AND SETTING THIS AS THE TRACKER CODE FOR EACH SESSION *******************************
            $dealer_id = mysql_insert_id(); //this would be the dealer_id autoincremented for this dealer row
            $_SESSION['trackerID'] = $dealer_id;
        }
        session_write_close();
        echo header("Location: Register2.php" );
}


//AT TOP OF PAGE ---I USE THE SESSION GLOBAL FUNCTION TO CALL THE SESSION FROM THE PREVIOUS PAGE
$trackerID = $_SESSION['trackerID'];
//************* IF THERE IS A BETTER WAY, PLEASE LET ME KNOW *****************************

//THEN THIS REGISTER PAGE 2, COLLECTS THE CONTACT INFORMATION FOR THE DEALER WHO JUST SET UP A USER NAME AND PASSWORD  ((((NOT SHOWING ALL OF THE VALIDATION CODE)))))

$query = ("INSERT INTO dealers (dealer_name, dealer_address, dealer_address2, dealer_city, dealer_state, dealer_country, dealer_zipcode,  dealer_Acode, dealer_phone, dealer_AcodeCell, dealer_cell, dealer_AcodeFax, dealer_fax, dealer_contact, dealer_salesContact, dealer_serviceContact, dealer_partsContact, db_password, trackerID)
VALUES ('".$_POST['dealer_name']."', '".$_POST['dealer_address']."', '".$_POST['dealer_address2']."', '".$_POST['dealer_city']."', '".$_POST['dealer_state']."', '".$_POST['dealer_country']."','".$_POST['dealer_zipcode']."', '".$_POST['dealer_Acode']."', '".$_POST['dealer_phone']."', '".$_POST['dealer_AcodeCell']."', '".$_POST['dealer_cell']."', '".$_POST['dealer_AcodeFax']."', '".$_POST['dealer_fax']."', '".$_POST['dealer_contact']."', '".$_POST['dealer_salesContact']."', '".$_POST['dealer_serviceContact']."', '".$_POST['dealer_partsContact']."', '".$_POST['db_password']."', '".$_SESSION['trackerID']."')");
$result = mysql_query($query);
$newDealer = mysql_fetch_array($result);      
if(!$newDealer)
            {
            echo "There has been an error creating your account.
            Please contact the webmaster." . mysql_error();
            }

        else {
//JUST TO CHECK AND SEE IF IT WORKS == AND TO PASS BELOW IN MAIL() FUNCTION.
    echo $newDealer['dealer_name'];
   }

THE REST IS THE MAIL FUNCTION WE WORKED ON ALL DAY!!!  SO I LEFT IT OFF.

Thank you so much!!!



that seems fine so far.
do you start session_start() as first statement on both pages?
Hope you were able to get some rest!!  
Yes, i worked all night and finally got this part working!!! yeah!!  My session code was not calling the session variable, but I finally got it to work!!
 
However, after i register and the email is sent  (thanks to you!! lol) .... then I clean the cookies, sessions, etc, and close the browser and reopen (to mimic what will happen with a user) and Log in...
How do I make the code recall the session that corresponds to this user?  I want to be able to recall their name and contact information in the warranty request.  Do I use a Cookie now, or can I just continue to use SESSIONS? A co-worker told me a cookie would work better, but I'm not sure!
This is what I have so far.... (snippets)

session_start();
require "dbt.php";
if(isset($_COOKIE[eCookie']))
//IF YOU ALREADY HAVE A COOKIE THAT MEANS YOU ARE OK TO LOG IN SO IT WILL Logs you in
//and direct you to Options page  SEE LINE 32*/
{`
      $d_email = $_COOKIE['eCookie'];
      $d_pass = $_COOKIE['pCookie'];
      $check = mysql_query("SELECT * FROM dealer_user WHERE d_email = '$d_email' ")or die(mysql_error());
            while($info = mysql_fetch_array( $check ))
            {
                  if ($d_pass != $info['d_pass'])
                  {
                  header("Location: login.php");
                  }
                  else
                  {
                  header("Location: options.php");
                  }
            }
//END COOKIE CHECKING HERE AND IF THE LOG IN FORM IS SUBMITTED, IT CHECKS INFO
}
//then, if the login form is submitted
if (isset($_POST['submit_login']))
{
        /* makes sure they filled it in*/
         }

      // check against the database name and password
        //Gives error if user dosen't exist
      //gives error if the d_pass is wrong
      //if login is ok then we add a cookie
      $_POST['d_email'] = stripslashes($_POST['d_email']);
                  $hour = time() + 0;//FOR TESTING PURPOSES
                  //SET TO EXPIRE WHEN BROWSER IS CLOSED at 0 closed or 3600 for 1 hour
                  setcookie(BBBeCookie, $_POST['d_email'], $hour, '/', '.mycompany.com');
                  setcookie(BBBpCookie, $_POST['d_pass'], $hour, '/', '.mycompany.com');

                           }
               }
session_write_close();                    
echo header("Location: options.php");
else
{//SHOW THE FORM
?>
HTML PART

---------- then the next options page shows three buttons from which they can choose....

-----------one of the options is a warranty request with another form

how do I connect these all together??  with the first register session, we set the session trackerID during INSERT INTO with mysql_insert_id(). and carried it over.  But, there is nothing inserted on these first two pages (only Select statement on first)?

THANK YOU!!! (again!)
I don't know why, but nothing I have tried is working...
Using the same $_SESSION variables on each page, but only transferring information on some pages, and not all.  Any suggestions?
>How do I make the code recall the session that corresponds to this user?  I want to be able to recall their name and contact information in the warranty request.  Do I use a Cookie now, or can I just continue to use SESSIONS? A co-worker told me a cookie would work better, but I'm not sure!

a cookie can help to suggest a automatic login for the user on that same computer.
however, is that REALLY what you want?

usually, you will need to store all his information in your database, and on login, read that from the db (and store in the session) ...

>Using the same $_SESSION variables on each page, but only transferring information on some pages, and not all.
that must be some programming/logic ... error.
for example, using $_SESSION["data"] vs $_SESSION["DATA"] vs $_SESSION["Data"] are 3 different items.
another problem could be somewhere, the session data is "reset" in your code before actually checking if it should be reset...

ok
AngelIII --- thank you for trying to help me... this has been such a frustrating situation and I have to finish it this week or I am fired!!!  I just don't know what else to do!!!  PLEASE HELP ME!!!

Here is the set up, without having to show all of the code..  if you need it, just let me know!!!

1) dealer registers with name and password === works fine and adds it to database fine
2) dealer is routed to second registration page where contact info if set == works fine and is added to database.  I carry the email address to the second page and echo it, so I know the sessions are working here.
3) email confirmation is sent -- problem here is that it shows the encrypted password (another issue later) but the email sends fine otherwise to the correct email address.
4) after the dealer checks email and confirms that he/she is registered, they go back to the site and login
5) Login sets a cookie, (with works great, if I am using the same computer over and over, or if the user does not delete their cookies in the mean time) and session variables (just in case they erase cookie) for the email address and password they $_POST in the login checking process.
6) if they are found in the database,(which works fine)
7) they are routed to a log in options page showing the various log in options ----

 THIS IS WHERE I LOOSE THEM. ----- Well, actually, I loose them between the login page and the login options page, because the information is not transferred from the login page to the login options page-----... i am using echo "<pre>"; print_r( $_SESSION ); echo "</pre>"; to check the $_SESSION array.  Sometimes I get one variable, sometimes all three, and sometimes none -- just says ARRAY { }.

8) Once they choose an option, they are routed to that page....
THIS IS MY HOPE AFTER WE FIX THE ABOVE ISSUE......

9) once on that page, they enter into a form which is saved to database
10) a confirmation page is printed for all of the information inserted so far
11) another email confirmation is sent
12) an option to print the page is available
13) they log out or go to another page in the site

If you want to see the code, please let me know.  Otherwise, the only other issue I have thought of is the fact that I use the same variable names for the COOKIES and the SESSIONS.
Does this matter?

Thank you so much for your help?
You have been a true Angel!!!
This is what I get after logging in

Array
(
    [d_email] =>
)
dealer login page login.php

session_start();
//START THE DATABASE RIGHT BEFORE YOU INSERT
require "dbStart.php";

/*---CHECK FOR COOKIE  --- THE ORIGINAL STUFF ---------------------*/

//IF YOU ALREADY HAVE A COOKIE THAT MEANS YOU ARE OK TO LOG IN SO IT WILL Logs you in
//and direct you to Options.PHP  SEE LINE 32*/

if(isset($_COOKIE['BBBeCookie']))
{
      $demail = $_COOKIE['BBBeCookie'];
      $dpass = $_COOKIE['BBBpCookie'];
      $check = mysql_query("SELECT * FROM dealeruser WHERE demail = '$demail' ")or die(mysql_error());
            while($info = mysql_fetch_array( $check ))
            {
                  if ($dpass != $info['dpass'])
                  {
                  header("Location: login.php");
                  }
                  else
                  {
                  /*TESTING WITH SESSIONS TO SEE IF IT HOLDS THE COOKIE FOR LOGIN*/
                  
                  header("Location: options.php");
                  }
            }
//END COOKIE CHECKING HERE AND IF THE LOG IN FORM IS SUBMITTED, IT CHECKS INFO
}
//then, if the login form is submitted
    if (isset($_POST['submit_login']))
    {
        // makes sure they filled it in
      // checks it against the database
         // if (!get_magic_quotes_gpc())
      //Gives error if user dosen't exist
      //while($info = mysql_fetch_array( $check ))
       {
        //check the password to see if it matches / exists  
        //******** putting password here makes it not read on login ---
            //PASS PASSWORD SESSION VARIABLE BEFORE IT IS ENCRYPTED
            //$_POST['dpass'] = ($_SESSION['dpass']);
       // **************now strip slashes and encrypt    
       //ENCRYPT THE PASSWORD HERE    
      $_POST['dpass'] = md5($_POST['dpass']);
      //gives error if the d_pass is wrong
                  if ($_POST['dpass'] != $info['dpass'])
                  {
                  die('Incorrect Dealer password, Use your [Back] button to return and try again!');
                  }
            //WITHOUT SLASHES
            else
            {
            $_POST['demail'] = stripslashes($_POST['demail']);
            //SET SESSION emai/passl VARIABLES  ***********COME BACK AND DO SECURITY LATER  
            $_POST['demail'] =($_SESSION['demail']);
            // posts the password encrypted here --- how to make not encrypted
            $_POST['dpass'] = ($_SESSION['dpass']);
 //------------------------------------------------------------------------------------
            //THEN*************************if login is ok then we add a cookie
            // SET COOKIE WITHOUT SLASHES
            //$_POST['demail'] = stripslashes($_POST['demail']);
            $hour = time() + 0;
                  //SET TO EXPIRE WHEN BROWSER IS CLOSED at 0 closed or 3600 for 1 hour
                  setcookie(BBBeCookie, $_POST['demail'], $hour, '/', '.companysite.com');
                  setcookie(BBBpCookie, $_POST['dpass'], $hour, '/', '.companysite.com');
 *************************************************************/    
        session_write_close();                    
//************************************************************            
            //then redirect them to the dealer Options area
        echo header("Location: options.php");
        } // END IF POST SUBMIT SET
    } //ELSE IF IT IS SET
}
else
{
//show the form

any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
           //SET SESSION emai/passl VARIABLES  ***********COME BACK AND DO SECURITY LATER  
            $_POST['demail'] =($_SESSION['demail']);
            // posts the password encrypted here --- how to make not encrypted
            $_POST['dpass'] = ($_SESSION['dpass']);

Should I have
$_SESSION['demail'] =  $_POST['demail']???
I followed another person's advice and did it the above way! Seems like everyone has their own way of doing things! lol
I will try this!!
It appears the trackerID code is now following along from page to page, but maybe this will help.
THANKS AGAIN!!
Well, with that switched around,(like above)  it is at least showing up at the top of the page with the print_r command.  I am using this (per Ray) to see if it even shows up.  Before I switched them around, the tracker ID was the only variable that would display.  Now....

1. The email and password shows if I log in
2. The TrackerID shows if I go to the beginning and register, then log in .
3. However, none of them show when I refresh the page.
According to Ray, I should be able to increment the page with refreshes, and they will show.
If the variables show up on the first submit, but don't show up on the second submit/refreshes, what does that mean? -------------- the time I have spent on this is getting to be almost a little crazy! lol
Thanks so much!!!  You've helped tremendously.
LA
This small example was the key to the solution!!  After looking at many, many other examples, the ones I found here at EE were the only answers which helped overcome the problem at hand.  Again thank you!!!