www.webdeveloper.com
Results 1 to 8 of 8

Thread: Simple Session and Email Question

  1. #1
    Join Date
    Dec 2007
    Posts
    129

    Exclamation Simple Session and Email Question

    We have 2 pages of php files. The first page gather the email address from the customer. The second page is the one that sends us the order email. I am not sure why we are not receiving the email. The thank you pages, are working correctly though.


    first file:
    PHP Code:
    <?php
    session_start
    ();
    $emailadr  '';
    $checkadr  '';
    $cr "\r";
    $lf "\n";
    $lterm $cr.$lf;
    $_SESSION['emailadr'] = $emailadr;

    if (
    $_SERVER['REQUEST_METHOD'] == 'POST'):
        
    $emailadr               $_POST['emailadr'];
        
    $checkadr              $_POST['checkadr'];
        
    $thankyou              "order2.php";
        
    header('Location: '.$thankyou);
    endif;
    ?>

    in html:
    HTML Code:
    <form action="<?=basename($_SERVER['PHP_SELF'])?>" method="post">
    <label>Your Email:  <input type="text" style="background-color: #FFF7C0; font-weight: bold" name="emailadr" size="25" value="<?=$emailadr?>"/> </label> (email used in your payment)<br><br>
    <label>Re-Type Your Email:  <input type="text" style="background-color: #FFF7C0; font-weight: bold" name="checkadr" size="25" value="<?=$checkadr?>"/> </label><br><br><br><br>
    <center>
    <button type='submit' value="SUBMIT" style="background-color:transparent; border: none"><img src = "../images/submit.png"/></button><br>
    Click <b>SUBMIT</b> button to continue<br><br>
    </center>
    </form>

    2nd php file:
    PHP Code:
    <?php
    session_start
    ();
    $thankyou    'thankyou.php';
    $mailcopy     'mailcopy@home.com';
    $mailcc     '';
    $mailsubj     'Your Order ';
    $fullname      '';
    $cr         "\r"
    $lf         "\n"
    $lterm         $cr.$lf
    $messages      ''
    $_SESSION['emailadr'] = $emailadr;

    if (
    $_SERVER['REQUEST_METHOD'] == 'POST'):
         
    $fullname          $_POST['fullname'];
         
    $thankyou         $_POST['thankyou'];
         
    $mailsubj         .= $fullname;

         if(
    strlen($messages)==0):
              
    $mailheaders 'Content-Type: text/plain;'.$lterm;
              
    $mailheaders .= 'X-Mailer: PHP;'.$lterm
              
    $mailheaders .= 'X-MSMail-Priority: High;'.$lterm
              
    $mailheaders .= 'X-Priority: 1;'.$lterm
              
    $mailheaders .= 'Return-path: '.$emailadr.$lterm
              
    $mailheaders .= 'Sender: '.$emailadr.$lterm
              
    $mailheaders .= 'From: '.$emailadr.$lterm
              if (isset(
    $mailcc
                   && !empty(
    $mailcc)): 
                       
    $mailheaders .= 'Cc: '.$mailcc.$lterm
              endif;
                   
    $mailbody "Your email address is:  $emailadr".$lterm;
              
    ini_set(sendmail_from$mailcopy); 
              if (
    mail($mailcopy$mailsubj$mailbody$mailheaders)): 
                   
    ini_restore(sendmail_from); 
                   
    header('Location: '.$thankyou);
                   exit; 
              endif; 
              
    ini_restore(sendmail_from); 
              
    $messages 'Failed to send email!'
         endif; 
    endif;
    ?>
    Last edited by xoxLISAxox; 04-14-2009 at 03:46 AM. Reason: Cleaned up code make it simpler

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,244
    Start by doing some basic debugging such as var_dump()-ing each of the variables used in the mail() function parameters to make sure they have the expected values (e.g.: is $emailadr actually set anywhere in the 2nd file?). If that looks OK, then try a very simple script that just sends an email using the same mail() settings and representative test parameters to see if its a mail configuration problem.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2007
    Posts
    129
    Hi NogDog:

    Yeah I think the problem is the variable emailadr. I thought I did it correctly on the top of the 2nd file, code posted above. I don't know how to do var_dump()-ing, lmao. I thought using:

    $_SESSION['emailadr'] = $emailadr;

    on the second file is making the variable $emailadr from the first file?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,244
    Any session values in the 2nd file will be in the $_SESSION array (unless you have the deprecated register_globals option is in effect). So you will need to populate $emailadr in the 2nd script from $_SESSION['emailadr'], or just use $_SESSION['email_adr'] instead of $emailadr. (And in the first file you will need to assign $emailadr to the $_SESSION array after you get the value from the form input.)

    var_dump() is just a PHP function that outputs the type and value of the specified variable, e.g.:
    PHP Code:
    $foo 'bar';
    echo 
    "The current value of \$foo is:<br />\n";
    var_dump($foo); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2007
    Posts
    129
    Hi:

    I did:

    echo $_SESSION['emailadr'];

    on the second file and it showed the email address from the first file. Why it's not sending the email I don't know

    Do I need to change the email part in the second file:

    PHP Code:
    $mailheaders .= 'From: '.$emailadr.$lterm
    to

    PHP Code:
    $mailheaders .= 'From: '.$_SESSION['emailadr'].$lterm
    That is the only place I see the variable is being used.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,244
    Yes, you have to grab the value from $_SESSION['emailadr']. The $emailadr variable will not automatically be created from it (again, this assumes you are not running with register_globals enabled, which you should not since it is deprecated and will not be available at all in PHP6).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Dec 2007
    Posts
    129
    That did the trick! Thank you so muchhhhhhh!!!

  8. #8
    Join Date
    Feb 2006
    Location
    Hedgesville WV
    Posts
    140
    Great Job NogDog. You are my favorite poster...
    Robert Ketter, www.RobertKetter.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles