I want to send an email with PHP when a user has finished filling in an HTML form and then emailing information from the form. I want to do it from the same script that displays the web page that has the form.
<?php // Email Submit // Note: filter_var() requires PHP >= 5.2.0 if (
isset($_POST['email']) && isset($_POST['name']) &&
isset($_POST['subject']) && isset($_POST['message']) &&
filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
// detect & prevent header injections $test = "/(content-type|bcc:|cc:|to:)/i"; foreach ( $_POST as $key => $val )
{
if ( preg_match( $test, $val ) ) {
exit;
} } $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion(); // mail( "#", $_POST['subject'], $_POST['message'], $headers
);
} ?>
Aucun commentaire:
Enregistrer un commentaire