Answer the question
In order to leave comments, you need to log in
How to make a feedback form in one php file?
Hello. There is a simple e-mail form sent through the handler email.php
<form name="form" id="form" method="post" action='email.php'>
<input type="text" name="name" id="name">
<input type="text" name="mail" id="mail">
<button type="button" id="button">Отправить</button>
</form>
$.post("email.php", $("#form").serialize(), function(result){
if(result == 'success'){
$('#form').fadeOut(500);
}else{
$('#form').html("<span class='red'>Fail!</span>");
}
});
$subject = $_REQUEST['subject'] . 'Новое письмо';
$to = '[email protected]';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: [email protected]'. "\r\n"
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$message .= '<b>Имя:</b> ' . $_REQUEST['name'] . "<br><br>";
$message .= '<b>Почта:</b> ' . $_REQUEST['mail'];
if (@mail($to, $subject, $message, $headers))
{
echo 'success';
}
else
{
echo 'fail';
}
Answer the question
In order to leave comments, you need to log in
If primitive:
And in index.php before displaying the form:
<?php
if (isset($_GET['action']))
{
/* Обработка и ответ */
}
Dokuro-chan So? For some reason it doesn't work.
<?php
if (isset($_POST['action']))
{
subject = $_REQUEST['subject'] . 'Новое письмо';
$to = '[email protected]';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: [email protected]'. "\r\n"
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$message .= '<b>Имя:</b> ' . $_REQUEST['name'] . "<br><br>";
$message .= '<b>Почта:</b> ' . $_REQUEST['mail'];
if (@mail($to, $subject, $message, $headers))
{
echo 'success';
}
else
{
echo 'fail';
}
}
?>
<script type="text/javascript">
$.post("index.php?action", $("#form").serialize(), function(result){
if(result == 'success'){
$('#form').fadeOut(500);
}else{
$('#form').html("<span class='red'>Fail!</span>");
}
});
</script>
<form name="form" id="form" method="post" action='email.php'>
<input type="text" name="name" id="name">
<input type="text" name="mail" id="mail">
<button type="button" id="button">Отправить</button>
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question