Connecting Tech Pros Worldwide Help | Site Map

Using PHP to extract all request variables

  #1  
Old July 17th, 2005, 01:53 PM
Luke Bellamy
Guest
 
Posts: n/a
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( "example@mail.com", "Web site contact request", $message, "From:
example@mail.com" );

Thankyou,
Luke Bellamy
Newcastle, Australia
  #2  
Old July 17th, 2005, 01:53 PM
Ewoud Dronkert
Guest
 
Posts: n/a

re: Using PHP to extract all request variables


On 28 Apr 2005 02:36:34 -0700, Luke Bellamy wrote:[color=blue]
> So I need to iterate through all the request variables on the contact
> form in a generic fashion.[/color]

$to = 'me@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/
  #3  
Old July 17th, 2005, 01:53 PM
David Gillen
Guest
 
Posts: n/a

re: Using PHP to extract all request variables


An noise sounding like Luke Bellamy said:[color=blue]
> 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.
>[/color]
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.
[color=blue]
> 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( "example@mail.com", "Web site contact request", $message, "From:
> example@mail.com" );
>
> Thankyou,
> Luke Bellamy
> Newcastle, Australia[/color]


--

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

  #4  
Old July 17th, 2005, 01:53 PM
Ken Robinson
Guest
 
Posts: n/a

re: Using PHP to extract all request variables



David Gillen wrote:[color=blue]
> An noise sounding like Luke Bellamy said:[color=green]
> > Hi,
> > I have several types of contact forms on my web site and when[/color][/color]
submit[color=blue][color=green]
> > is hit I would like the PHP code to build a string with each[/color][/color]
variable[color=blue][color=green]
> > name and value and dump it in an email to me.
> > So I need to iterate through all the request variables on the[/color][/color]
contact[color=blue][color=green]
> > 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[/color][/color]
below[color=blue][color=green]
> > to send an email.
> >[/color]
> 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.[/color]

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

  #5  
Old July 17th, 2005, 01:53 PM
Philip Olson
Guest
 
Posts: n/a

re: Using PHP to extract all request variables


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.

  #6  
Old July 17th, 2005, 01:54 PM
MsKitty
Guest
 
Posts: n/a

re: Using PHP to extract all request variables


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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using HTML Forms to pass data to PHP Atli insights 12 June 2nd, 2008 10:30 AM
XMLHttpRequest and AJAX for PHP programmers geevaa answers 1 March 27th, 2007 01:55 PM
Best approach to run queries only when user chooses Ian Davies answers 8 October 26th, 2005 12:55 AM
python-dev Summary for 2005-04-16 through 2005-04-30 Tony Meyer answers 7 July 19th, 2005 02:20 AM