Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail form (send keya/values)

Status
Not open for further replies.

jozino01

Technical User
Joined
Apr 25, 2003
Messages
257
Location
CA
Hi,

I have this very simple script to mail form:

<?php
$redirectURL = "$arr = get_defined_vars();
$mailBody=implode(" , ",$arr[HTTP_POST_VARS]) . "\n\n";
$email="hujo@nextra.sk";
$mailHeaders = "From: info@mysite.sk\r\n";
$mailSubject = "Online objednavka";
mail($email, $mailSubject, $mailBody, $mailHeaders);
header("Location: ".$redirectURL);
?>

It works fine - it sends all values divided by commas in a row (value1, value2, value3, etc)

Would it be possible to update this script so it would send also keys/field names (key1: value1, key2: value2, key3: value3, etc)?
I know almost nothing about PHP, just need update this one script.
Thanks.
 
Just write a foreach loop:
Code:
foreach ($_POST as $key => $value){
   $mailBody .= $key.':'.$value.',';
}
You can choose how to format this easily.
 
Thanks; do you mean to replace the line:

$mailBody=implode(" , ",$arr[HTTP_POST_VARS]) . "\n\n";

with your code:

foreach ($_POST as $key => $value){
$mailBody .= $key.':'.$value.',';
}

right?
 
Yes, that's what I mean. Be sure to attach the two newlines (not in the sample).
 
Oops, what other two new lines?
 
I believe there should be two new-line characters after the message body.
Code:
foreach ($_POST as $key => $value){
   $mailBody .= $key.':'.$value.',';
}
[COLOR=red]
$mailBody .= "\n\n";
[/color]
 
I will do that, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top