Page 1 of 1
[RESOLVED] Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 6:05 am
by 124112
I am trying to put a script on my site, that has 5 textboxes, and a submit button.
When the user presses submit, I want to be emailed the information they put, with linebreaks, like this:
Info1: txt1
Info2: txt2
Info3: txt3
Info4: txt4
Info5: txt5
The code I have that grabs the data from the textbox is
And the line of code that sends the email is
Code: Select all
mail($to,$subject,$message,$headers);
Is there a way I can, in the $message variable, have multiple POST requests that gets all the fields the user put, and puts inline linebreaks between each of them?
Tell me I haven't explained my problem clearly.
Re: Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 6:11 am
by VladSun
implode() the $_POST array

Re: Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 6:15 am
by steel_rose
Hi,
I think your best soution would be to use a foreach loop.
Code: Select all
foreach ($_POST as $key=>$val){
echo "$key: $val <br />";
}
Let me know if this is what you looking for, good luck with your code!
SR
Re: Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 9:27 am
by 124112
steel_rose wrote:Hi,
I think your best soution would be to use a foreach loop.
Code: Select all
foreach ($_POST as $key=>$val){
echo "$key: $val <br />";
}
Let me know if this is what you looking for, good luck with your code!
SR
Thanks to both of you guys, but I am getting an error.
This is my code:
Code: Select all
$message = foreach ($_POST as $key=>$val){ echo "$key: $val <br />"; };
And I get this error:
Parse error: syntax error, unexpected T_FOREACH in /home/test/public_html/send.php on line 4
I'm prettty sure I am doing something horribly wrong. How should I do this? What should go after "$message =" ?
Re: Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 9:33 am
by buckit
This should work (untested)
Code: Select all
foreach ($_POST as $key=>$val){ $message .= "$key: $val <br />"; };
.= will append to the existing value of $message. So it keeps adding to it as it loops.
Re: Multiple $_POST in variable?
Posted: Wed Jul 14, 2010 9:48 am
by 124112
buckit wrote:This should work (untested)
Code: Select all
foreach ($_POST as $key=>$val){ $message .= "$key: $val <br />"; };
.= will append to the existing value of $message. So it keeps adding to it as it loops.
Thanks to all 3 of you who helped me with this problem.
I finally got it working with this:
Code: Select all
foreach ($_POST as $key=>$val){ $message .= "$key: $val \n"; };
I had to use \n instead of <br>