473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 15723
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Logical | last post by:
I wanted to do: include('page.htm?id=12&foo=bar'); But since I can't (and don't want to make another seperate HTTP request with include('http://...')); I was wondering if there's a function...
7
by: Jonas Daunoravicius | last post by:
The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script language="javascript" type="text/javascript"> function...
0
by: Fraser Dickson | last post by:
I am building a web based system using ASP.NET and VB.NET which has to interact with a web service which uses XML WDDX packets. I have been given the XML Packet Specification by the Web Service...
0
by: anoop | last post by:
Hello, I want to write the VB code to extract value from QueryString property using ASP.Net, the following code should be written in The Form's Action property. Dim loop1, loop2 As Integer...
11
by: pmarisole | last post by:
I am using the following code to split/join values in a multi-select field. It is combining all the values in All the records into one long string in each record in recordset. Example: I have a...
10
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
10
by: Sudhakar | last post by:
i am using $ip= $_SERVER to retrieve the ip address of the client for example if the value returned from $ip is 50.160.190.150 i would like to find out which country the request has come from. i...
3
bilibytes
by: bilibytes | last post by:
Hi everyone, I am wondering if it is possible to extract the key values of an array into object variables. lets say i have the following $_REQUEST array: $var_array = array("color" =>...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.