473,561 Members | 3,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_FullNa me'] .
"\n";
$message = $message . "Title: " . $_REQUEST['Contact_Title'] . "\n";

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

Thankyou,
Luke Bellamy
Newcastle, Australia
Jul 17 '05 #1
5 15743
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($_REQUE ST);
$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_FullNa me'] .
"\n";
$message = $message . "Title: " . $_REQUEST['Contact_Title'] . "\n";

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

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($_REQUE ST);
$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($_REQUE ST,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_FullNa me' => '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_gp c 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
OpenSkyWebDesig n.com

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2056
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 similar to extract(); that can handle a query string as input, so that I could: $id = 12; $foo = 'bar'; include('page.htm');
7
72127
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 fillForm() { // split the query string into pieces var qs = location.search.substr(location.search.indexOf("?")+1); qs = qs.split("&"); alert(qs);...
0
1892
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 Provider but can't work out the best way to interact with the WDDX packets. Basically the way the Web Service works is that you send a WDDX...
0
1700
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 Dim arr1(), arr2() As String Dim coll As NameValueCollection
11
12584
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 recordset with 2 records. The 1st contains the split/joined values: Alan Smir, Jeff Karl The 2nd contains the value: Keith Robb When it updates...
10
2244
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 based on some dropdown boxes, one for the year and one for the month. This line saves the file so I am trying to get the month and year from the...
6
5127
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 application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and...
10
2013
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 believe by using the third set of numbers (in this case=190) from an ip address we can find out the country name. i can declare a variable with a...
3
6457
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" => "blue", "size" => "medium", "shape" => "sphere");
0
7565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8079
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5182
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3613
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3595
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
888
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.