Form values โโgo into arrays and email them without working in PHP
I'm trying to submit form values โโusing foreach to send email, but doesn't work.
My mistake: I receive email. But the last value is Only.
My form code
<form action="index.php" method="POST">
Name : <input type="text" name="name">
Email : <input type="text" name="email">
Message : <textarea name="message"></textarea>
<input type="submit">
</form>
My PHP Code
if(isset($_POST['name'])){
$data = $_POST;
$arrays = serialize($data);
$decod = unserialize($arrays);
foreach($decode as $key => $value) {
$message = '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
$headers = "From: info@fetilepix.com" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$emailbody = $message;
mail('rajasekarang.cud@gmail.com','Contacts From Website',$emailbody,$headers);
}
?>
+3
source to share
1 answer
change
foreach($decode as $key => $value) {
$message = '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
to
foreach($decode as $key => $value) {
$message.= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
Your values โโwill be overwritten with the next value according to the loop, you may need to add data to $message
rather than adding a new value every time.
+3
source to share