Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all POST data and send in email

Tags:

php

email

mysql

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?

like image 396
Liam Avatar asked Nov 05 '12 12:11

Liam


2 Answers

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.

like image 188
Mitch Satchwell Avatar answered Sep 28 '22 11:09

Mitch Satchwell


$message = "";
foreach ($_POST as $key => $value)
$message .= "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";

mail('[email protected]', 'sghting', $message);
like image 38
Vikash Kumar Avatar answered Sep 28 '22 11:09

Vikash Kumar