<form id="form" class="form-horizontal">
<fieldset>
<div class="control-group">
<input type="text" id="name" name="name" placeholder="имя" class="input-xlarge" required="required" />
</div>
<div class="control-group">
<input type="text" id="email" name="email" placeholder="email" class="input-xlarge" required="required"/>
</div>
<div class="control-group">
<input type="text" id="subject" name="subject" placeholder="тема" class="input-xlarge" required="required"/>
</div>
<div class="control-group">
<textarea rows="3" id="msg" name = "msg" class="input-xlarge" placeholder="Укажите причину" required="required" >
</textarea>
</div>
<button class="btn btn-large btn-success" type="submit" onclick="mail();">Отправить</button>
</fieldset>
</form>
function sendAction() {
$name = trim(htmlspecialchars($_REQUEST['name']));
$email = trim(htmlspecialchars($_REQUEST['email']));
$subject = trim(htmlspecialchars($_REQUEST['subject']));
$msg = trim(htmlspecialchars($_REQUEST['msg']));
$headers = '';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8 \r\n"; //Кодировка письма
$headers .= "From: Отправитель < $email >\r\n"; //Наименование и почта
if ( (!empty($name)) && ( !empty($email)) && ( !empty($subject)) && ( !empty($msg))) {
$to = 'fly_life@mail.ru';
$message = "Имя: $name \nПочта: $email \nТема: $subject \nТекст: $msg";
$resData = mail($to, $subject, $message, $headers);
if ($resData['success']) {
$resData['success'] = 1;
$resData['message'] = 'Письмо отправлено!';
} else {
$resData['success'] = 0;
$resData['message'] = 'Ошибка отправки!';
}
echo json_encode($resData);
} else {
redirect('/');
}
}
function mail() {
var name = $('#name').val();
var email = $('#email').val();
var subject = $('#subject').val();
var msg = $('#msg').val();
var postData = 'name='+name+'&email='+email+'&subject=' +subject+'&msg=' +msg;
$.ajax({
type: 'POST',
async: true,
url: '/contact/send/',
data: postData,
dataType: 'json',
success: function (data) {
console.log(data['message']);
if(data['success']) {
alert(data['message']);
}else{
alert(data['message']);
}
}
})
}
var name = $('#name').val();
var email = $('#email').val();
var subject = $('#subject').val();
var msg = $('#msg').val();
var postData = 'name='+name+'&email='+email+'&subject=' +subject+'&msg=' +msg;
var postData = $('.form-horizontal').serialize();