Answer the question
In order to leave comments, you need to log in
Gmail.com does not accept letters from the mail() function in the php script because of the $header, how to set it up?
there is a php script that sends letters, and for mailers like mail.ru or yandex.ru it works correctly, that is, letters arrive, but gmail.com refuses to accept them (not even in spam), most likely the matter is in setting $ headers , help me set it up so that gmail.com can receive emails. here is the code:
<?php
header('Content-Type: text/html; charset=utf-8');
/* Проверка на заполнение полей */
if (isset($_POST['phone'])) {
$name = $_POST['name'];
$tel = $_POST['phone'];
$email = $_POST['email'];
$referer = $_POST['referer'];
$title = $_POST['title'];
/* Убираем все лишние пробелы и переносы строк и преобразуем все теги html в символы*/
$name = htmlspecialchars(trim($name));
$tel = htmlspecialchars(trim($tel));
$email = htmlspecialchars(trim($email));
/* Формируем сообщение */
$mail = "***@***.ru";
$subject = $title; //тема письма
$message = "<html><head></head><body>";
$message .= "***";
$message .= "</body></html>";
$mess = "<html><head></head><body>";
$mess .= "Благодарим Вас за оставленную заявку!<br>";
$mess .= "если у Вас возникли вопросы напишите нам по адресу: $mail";
$mess .= "</table></body></html>";
function adopt($text) {
return '=?UTF-8?B?'.base64_encode($text).'?=';
}
$headers = "MIME-Version: 1.0".PHP_EOL."Content-Type: text/html; charset=utf-8".PHP_EOL.'From: '.adopt('***').' <[email protected]***.ru>'.PHP_EOL;
/* Отправка */
$sendmail = mail ($mail,$subject,$message,$headers);
$sendmail_2 = mail ($email,$subject,$mess,$headers);
echo $title;
}
?>
Answer the question
In order to leave comments, you need to log in
Of the obvious problems - there is no header Content-Transfer-Encoding: 8bit, it is needed, because. there are non-ASCII characters in the message and no Date and Message-ID are generated.
But most likely, the problem is complex, read
https://habrahabr.ru/company/mailru/blog/239963/
and check everything point by point, especially SPF / DKIM, GMail is very suspicious of mail without authentication.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question