На сайте выдаёт ошибку,(Не удалось отправить Вашу заявку. Попробуйте еще раз). Много времени потратил разбираясь что к чему и не получается исправить. Помогите разобраться и как исправить. Тестовый домен ссылка
Было так.
define("__TO__", "info@remont-okon-berdsk.ru");
define('__SUCCESS_MESSAGE__', "Ваша заявка успешно отправлена. Мы ответим как можно скорее!");
define('__ERROR_MESSAGE__', "Не удалось отправить Вашу заявку. Попробуйте еще раз.");
define('__MESSAGE_EMPTY_FIELDS__', "Пожалуйста, заполните все поля");
//E-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
//Send mail
function send_mail($to, $subject, $message, $headers){
if(@mail($to, $subject, $message, $headers, __TO__)) {
echo json_encode(array('status' => true, 'msg' => __SUCCESS_MESSAGE__));
} else {
echo json_encode(array('status' => false, 'msg' => __ERROR_MESSAGE__));
}
}
//Get data form and send mail
if(isset($_POST['phone']) && isset($_POST['subject'])){
$phone = htmlspecialchars($_POST['phone']);
$subject = htmlspecialchars($_POST['subject']);
$title = 'Сообщение от ';
if (!empty($_POST['username'])) {
$title .= htmlspecialchars($_POST['username']);
}
else {
$title .= $phone;
}
if(empty($phone) || mb_strlen($phone) < 5) {
echo json_encode(array('info' => 'error', 'msg' => "Введите корректный телефон."));
exit();
} else if(empty($subject)){
echo json_encode(array('info' => 'error', 'msg' => "Ошибка отправки заявки."));
exit();
} else {
$to = __TO__;
$message = '
<html>
<head>
<title>' .$title .'</title>
</head>
<body>
<table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Тема сообщения:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $subject .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Телефон:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $phone .'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' .__TO__ ."\r\n";
send_mail($to, $subject, $message, $headers);
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FIELDS__));
}
?>
А стало так правильно?
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
define("__TO__", "info@remont-okon-berdsk.ru");
define('__SUCCESS_MESSAGE__', "Ваша заявка успешно отправлена. Мы ответим как можно скорее!");
define('__ERROR_MESSAGE__', "Не удалось отправить Вашу заявку. Попробуйте еще раз.");
define('__MESSAGE_EMPTY_FIELDS__', "Пожалуйста, заполните все поля");
//E-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
//Send mail
function send_mail($to, $subject, $message, $headers){
if(@mail($to, $subject, $message, $headers, __TO__)) {
echo json_encode(array('status' => true, 'msg' => __SUCCESS_MESSAGE__));
} else {
print_r(error_get_last());
echo json_encode(array('status' => false, 'msg' => __ERROR_MESSAGE__));
}
}
//Get data form and send mail
if(isset($_POST['phone']) && isset($_POST['subject'])){
$phone = htmlspecialchars($_POST['phone']);
$subject = htmlspecialchars($_POST['subject']);
$title = 'Сообщение от ';
if (!empty($_POST['username'])) {
$title .= htmlspecialchars($_POST['username']);
}
else {
$title .= $phone;
}
if(empty($phone) || mb_strlen($phone) < 5) {
echo json_encode(array('info' => 'error', 'msg' => "Введите корректный телефон."));
exit();
} else if(empty($subject)){
echo json_encode(array('info' => 'error', 'msg' => "Ошибка отправки заявки."));
exit();
} else {
$to = __TO__;
$message = '
<html>
<head>
<title>' .$title .'</title>
</head>
<body>
<table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Тема сообщения:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $subject .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Телефон:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $phone .'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$header = "Content-Type: text/plain; charset=utf-8\n";
$header .= "From: Новая заявка <test@gmail.com>\n\n";
$mail = mail("test@gmail.com", "test", "test", $header); // ale-valujskikh@yandex.ru
if($mail){
echo 'OK';
} else {
echo 'Ошибка с mail()';
}
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FIELDS__));
}
?>