forms sessions email

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Quinonez

    forms sessions email

    here is the set up.
    7 page form all get set to sessions
    8th page sessions are called and results displayed for user to see
    this is the php script for page 8
    <?
    ksort($_SESSION );
    foreach ($_SESSION as $page=>$_POST)
    {
    echo "<div class=\"h3\">$p age</div><br>";
    foreach ($_POST as $field=>$value)
    {
    echo "$field: $value<br>";
    }
    }
    ?>

    now i would like for the user to press a submit link/button and the
    results sent to an email address. i know how to set up basic feedback
    forms and have them emailed to me but not really sure where to go from
    here once i ve called the sessions to recall them on another page.. any
    help greatly appreciated.
    thank you

  • lig

    #2
    Re: forms sessions email

    Quinonez wrote:[color=blue]
    > here is the set up.
    > 7 page form all get set to sessions
    > 8th page sessions are called and results displayed for user to see
    > this is the php script for page 8
    > <?
    > ksort($_SESSION );
    > foreach ($_SESSION as $page=>$_POST)
    > {
    > echo "<div class=\"h3\">$p age</div><br>";
    > foreach ($_POST as $field=>$value)
    > {
    > echo "$field: $value<br>";
    > }
    > }
    > ?>
    >
    > now i would like for the user to press a submit link/button and the
    > results sent to an email address. i know how to set up basic feedback
    > forms and have them emailed to me but not really sure where to go[/color]
    from[color=blue]
    > here once i ve called the sessions to recall them on another page..[/color]
    any[color=blue]
    > help greatly appreciated.
    > thank you[/color]


    While you are loading the HTML page for display you could also load it
    into the message variable of the email. Don't forget emails can be in
    the HTML format also. You could litereally send yourself the page the
    user sees. Ahhh and session variables may be called and recalled as
    many times as you want.

    Basic logic:
    if (submitted)
    {
    create the HTML page to be displayed and save it into the
    variable $body.

    Example: ksort($_SESSION );
    foreach ($_SESSION as $page=>$_POST)
    {
    message .= "<div class=\"h3\">$p age</div><br>";
    foreach ($_POST as $field=>$value)
    {
    message .= "$field: $value<br>";
    }
    }
    echo $message;
    mail($to, $subject, $message, $headers);
    }

    Make sense?

    Reference: mail:
    http://www.php.net/manual/en/function.mail.php - Note example 4
    Sessions:




    Comment

    • Pedro Graca

      #3
      Re: forms sessions email

      Quinonez wrote:[color=blue]
      > now i would like for the user to press a submit link/button and the
      > results sent to an email address. i know how to set up basic feedback
      > forms and have them emailed to me but not really sure where to go from
      > here once i ve called the sessions to recall them on another page.. any
      > help greatly appreciated.[/color]

      First: indent your scripts.


      then ...

      Build a string with the info from the $_SESSION and then mail it.

      [copied from your code and reformatted]
      <?php
      ksort($_SESSION );

      /* initializae $msg_body */
      $msg_body = '';

      foreach ($_SESSION as $page=>$_POST)
      {
      # echo "<div class=\"h3\">$p age</div><br>";

      /* add $page to message */
      $msg_body .= "\n$page\n" ;

      foreach ($_POST as $field=>$value)
      {
      # echo "$field: $value<br>";

      /* add $field and $value to message */
      $msg_body .= "$field: $value\n";

      }
      }

      /* send it */
      if (!mail($somebod y, 'Form contents', $msg_body)) {
      /* mail not sent! */
      /* write error_log or something :-) */
      }

      ?>

      --
      Mail to my "From:" address is readable by all at http://www.dodgeit.com/
      == ** ## !! ------------------------------------------------ !! ## ** ==
      TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
      may bypass my spam filter. If it does, I may reply from another address!

      Comment

      • Quinonez

        #4
        Re: forms sessions email

        i tried this version and it sent the email but it sent 6 different
        emails one for each page....and also send teh PHPSESSID

        Comment

        • Quinonez

          #5
          Re: forms sessions email

          i got it to work now my only prob is the PHPSESSID...any one know how to
          get this to not show?

          Comment

          • Pedro Graca

            #6
            Re: forms sessions email

            Quinonez wrote:[color=blue]
            > i got it to work now my only prob is the PHPSESSID...any one know how to
            > get this to not show?[/color]

            Why is the PHPSESSID in the $_SESSION array?

            If you can't remove it from there, at the moment you're building the
            message, check whether the current key is 'PHPSESSID' and do not add it
            to the message.
            --
            Mail to my "From:" address is readable by all at http://www.dodgeit.com/
            == ** ## !! ------------------------------------------------ !! ## ** ==
            TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
            may bypass my spam filter. If it does, I may reply from another address!

            Comment

            • Quinonez

              #7
              Re: forms sessions email

              the problem is its generating automatically because of the code. so i
              dont know how to take PHPSESSID out? or not include it

              Comment

              • Pedro Graca

                #8
                Re: forms sessions email

                Quinonez wrote:[color=blue]
                > the problem is its generating automatically because of the code. so i
                > dont know how to take PHPSESSID out? or not include it[/color]


                unset($saved_se ssid); /* to make sure it doesn't exist */

                if (isset($_SESSIO N['PHPSESSID'])) {
                $saved_sessid = $_SESSION['PHPSESSID'];
                unset($_SESSION['PHPSESSID']); /* remove it from the $_SESSION */
                }

                /* do your printing stuff here */

                /* restore $_SESSION, it might be needed by php */
                if (isset($saved_s essid)) {
                $_SESSION['PHPSESSID'] = $saved_sessid;
                unset($saved_se ssid); /* save a few bytes of memory */
                }

                --
                Mail to my "From:" address is readable by all at http://www.dodgeit.com/
                == ** ## !! ------------------------------------------------ !! ## ** ==
                TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
                may bypass my spam filter. If it does, I may reply from another address!

                Comment

                Working...