Reputation: 9855
Im trying to use PHP Mail function to send myself an email of all post variables.
So far I have this...
$message = foreach ($_POST as $key => $value)
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
$message = wordwrap($message, 70);
mail('[email protected]', 'sghting', $message);
Only the message being submitted is my last post record, can anybody see where im going wrong?
Upvotes: 10
Views: 11522
Reputation: 391
I personally just use var_export()
for this kind of thing.
$message = var_export($_POST,true);
If used and set to TRUE, var_export() will return the variable representation instead of outputting it.
Practice example would be:
mail('[email protected]', 'Export of the Post Data', var_export($_POST,true));
OR if you want to do something more pretty
$posted_data = var_export($_POST,true);
$message = '
<h4> Debug Registration Form on XXX </h4>
<p>Here is a dump of the posted data</p>
<pre>
'.$posted_data.'
</pre>
';
mail('[email protected]', 'Export of the Posted Data', $message);
Upvotes: 1
Reputation: 222
$message = "";
foreach ($_POST as $key => $value)
$message .= "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
mail('[email protected]', 'sghting', $message);
Upvotes: 1
Reputation: 4830
foreach ($_POST as $key => $value)
$message .= "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
mail('[email protected]', 'sghting', $message);
$message = foreach ($_POST as $key => $value)
is not correct, this will iterate over the results and store the last one. You want to store the values in your $message variable, not echo them.
Upvotes: 19