POST http://www.site.ru/ajax/callback 500 (Internal Server Error)
<div id="callback" class="mfp-hide magpop mfp-with-anim">
<form action="#" class="pop_form" method="post">
<div class="f_tit">Обратный звонок</div>
<fieldset>
<label>
<input type="text" name="" value="" placeholder="Ваше имя" autofocus="autofocus" id="name4" class="f_field">
</label>
</fieldset>
<fieldset>
<label>
<input type="text" name="" value="" placeholder="Ваш телефон" id="phone4" class="f_field">
</label>
</fieldset>
<input type="submit" name="" value="Отправить" class="f_btn btn form_btn4">
</form>
</div>
public function action_callback() {
$name = Arr::get($_POST, 'name');
$title = ' Письмо!';
$mailer = new Mailer();
$mailer->setSubject($title);
$mailer->setFrom('info@site.ru');
$mails = Settings::get('emails');
$mails = explode(';', $mails);
$mails = array_map('trim', $mails);
$mails = array_diff($mails, array(''));
$mails[] = 'mail@gmail.com';
$mailer->setTo($mails);
$body = 'Имя: ' . $name . '<br>';
$body .= ' Телефон: ' . Arr::get($_POST, 'phone') . '<br>';
$mailer->setBody($body, 'text/html');
$mailer->sendNotification(true);
return $name;
}
$(".form_btn4").on("click", function () {
var name = $('#name4').val();
var phone = $('#phone4').val();
if (name == '' || phone == '') {
alert("Заполните все поля");
return false;
}
$.ajax({
type: "POST",
url: "/ajax/callback",
data: {name: name, phone: phone},
success: function () {
alert('Отправлено');
$('.form').trigger('reset');
}
});
});