Sending All Form Data Via Email
mail('recipient@example.com', 'Form data', $text);
|
A more imminent notification of someone filling out a form can be implemented by sending form data via email. Of course, you can write a custom mail script for each and every form; however, the preceding code shows how this can be done universally. Via for, all form data is merged into a string. Special care is taken of form values that are arraysthis can occur with multiple selection lists. Then the form data is mailed to the webmasterjust don't forget to change the email address.
Sending Form Data Via Email (form-mail.php; excerpt)
<?php
require_once 'stripFormSlashes.inc.php';
?>
...
<?php
if (isset($_POST['Submit']) &&
isset($_POST['fieldname']) &&
trim($_POST['fieldname']) != '' &&
$_POST['groupname'] != '') {
echo '<h1>Thank you for filling out this
form!</h1>';
$text = '';
foreach ($_POST as $name => $value) {
if (is_array($value)) {
$text .= sprintf("%s: %s\n", $name, join('
', $value));
} else {
$text .= sprintf("%s: %s\n", $name, $value);
}
}
mail('recipient@example.com', 'Form data',
$text);
} else {
?>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']); ?>">
...
</form>
<?php
}
?>
|