Как подключить к форме в html php-файл, для отправки сообщений с сайта?
В index.html имеется следующая форма отправки сообщений:
<form>
<input type="text" placeholder="Ваше имя...">
<input type="email" placeholder="Ваш Email...">
<textarea placeholder="Ваше сообщение..."></textarea>
<input type="submit" value="Отправить →" class="dropsubmitbtn">
</form>
Файл send_mail.php выглядит так:
<?php
$webmaster_email = "mail@mail.ru";
$feedback_page = "index.html";
$error_page = "error.html";
$thankyou_page = "thanks.html";
$name = $_REQUEST['name'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['message'] ;
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}
// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}
// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email", "Message from your Atlas site",
$name, $comments, "From: $email_address" );
header( "Location: $thankyou_page" );
}
?>