By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

forms sessions email

P: n/a
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\">$page</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

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
lig
Quinonez wrote:
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\">$page</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

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\">$page</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:
http://us2.php.net/variables.predefined
http://us2.php.net/manual/en/reserve...iables.session
http://us2.php.net/manual/en/ref.session.php

Jul 17 '05 #2

P: n/a
Quinonez wrote:
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.


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\">$page</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($somebody, '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!
Jul 17 '05 #3

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

Jul 17 '05 #4

P: n/a
i got it to work now my only prob is the PHPSESSID...anyone know how to
get this to not show?

Jul 17 '05 #5

P: n/a
Quinonez wrote:
i got it to work now my only prob is the PHPSESSID...anyone know how to
get this to not show?


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!
Jul 17 '05 #6

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

Jul 17 '05 #7

P: n/a
Quinonez wrote:
the problem is its generating automatically because of the code. so i
dont know how to take PHPSESSID out? or not include it

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

if (isset($_SESSION['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_sessid)) {
$_SESSION['PHPSESSID'] = $saved_sessid;
unset($saved_sessid); /* 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!
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.