472,126 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Using PHP to extract all request variables

Hi,
I have several types of contact forms on my web site and when submit
is hit I would like the PHP code to build a string with each variable
name and value and dump it in an email to me.
So I need to iterate through all the request variables on the contact
form in a generic fashion.
Can someone please let me know the best way to do this?
I am very new to PHP so feel free to point out a better way than below
to send an email.

At the moment it's like this but I explicitly have to extract each
request variable:
$message = "A contact request from the web site has been
received.\n\n";
$message = $message . "Full Name: " . $_REQUEST['Contact_FullName'] .
"\n";
$message = $message . "Title: " . $_REQUEST['Contact_Title'] . "\n";

//echo $message;
mail( "ex*****@mail.com", "Web site contact request", $message, "From:
ex*****@mail.com" );

Thankyou,
Luke Bellamy
Newcastle, Australia
Jul 17 '05 #1
5 15621
On 28 Apr 2005 02:36:34 -0700, Luke Bellamy wrote:
So I need to iterate through all the request variables on the contact
form in a generic fashion.


$to = 'm*@privacy.net';
$subj = 'Test';
$msg = 'Requested:\n';
foreach ( $_REQUEST as $k => $v )
$msg .= "\t$k = $v\n";
mail( $to, $subj, $msg );
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #2
An noise sounding like Luke Bellamy said:
Hi,
I have several types of contact forms on my web site and when submit
is hit I would like the PHP code to build a string with each variable
name and value and dump it in an email to me.
So I need to iterate through all the request variables on the contact
form in a generic fashion.
Can someone please let me know the best way to do this?
I am very new to PHP so feel free to point out a better way than below
to send an email.
ob_start();
print_r($_REQUEST);
$stuff = ob_get_contents();
ob_end_clean();

Then mail $stuff to yourself.
You could also use $_POST or $_GET as appropriate.

D.
At the moment it's like this but I explicitly have to extract each
request variable:
$message = "A contact request from the web site has been
received.\n\n";
$message = $message . "Full Name: " . $_REQUEST['Contact_FullName'] .
"\n";
$message = $message . "Title: " . $_REQUEST['Contact_Title'] . "\n";

//echo $message;
mail( "ex*****@mail.com", "Web site contact request", $message, "From:
ex*****@mail.com" );

Thankyou,
Luke Bellamy
Newcastle, Australia

--

/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.

Jul 17 '05 #3

David Gillen wrote:
An noise sounding like Luke Bellamy said:
Hi,
I have several types of contact forms on my web site and when submit is hit I would like the PHP code to build a string with each variable name and value and dump it in an email to me.
So I need to iterate through all the request variables on the contact form in a generic fashion.
Can someone please let me know the best way to do this?
I am very new to PHP so feel free to point out a better way than below to send an email.

ob_start();
print_r($_REQUEST);
$stuff = ob_get_contents();
ob_end_clean();

Then mail $stuff to yourself.
You could also use $_POST or $_GET as appropriate.


There is an optional argument to the print_r function, when set to
TRUE, will return the output instead of printing it.

$stuff = print_r($_REQUEST,TRUE);

See www.php.net/print_r

Ken

Jul 17 '05 #4
How about defining one variable as to only include stuff you want, feel
free to add to this variable :)

$message = "A contact request...";
$variables = array(
'Contact_FullName' => 'Full Name',
'Contact_Title' => 'Title'
);
foreach ($variables as $variable => $title) {
$message .= "$title:\t" . $_REQUEST[$variable] . "\n";
}

Also, don't forget to deal with the magic_quotes_gpc directive.

Jul 17 '05 #5
There are lots of PHP form mail type scripts out there that do this.
The onel I use is Jack's formmail - available free here
http://dtheatre.com/scripts/

kitty
OpenSkyWebDesign.com

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Logical | last post: by
reply views Thread by Fraser Dickson | last post: by
6 posts views Thread by =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post: by
10 posts views Thread by Sudhakar | last post: by
bilibytes
3 posts views Thread by bilibytes | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.