D
D
Dmitry2018-05-13 13:19:00
gmail
Dmitry, 2018-05-13 13:19:00

Why requests from the site sent to gmail end up in spam?

Hello!
What can be done in this case? I use a simple form to send name and phone number:

<form id="callback" class="form-callback">
  
  <input type="hidden" name="project_name" value="Название компании">
  <input type="hidden" name="admin_email" value="[email protected]">
  <input type="hidden" name="form_subject" value="Заявка с сайта domen.ru">

  <input type="text" name="Имя" placeholder="Ваше имя...">

  <input type="text" name="Телефон" placeholder="Ваш телефон..." required>

  <button class="button">Отправить</button>

</form>

$method = $_SERVER['REQUEST_METHOD'];

//Script Foreach
$c = true;
if ( $method === 'POST' ) {

  $project_name = trim($_POST["project_name"]);
  $admin_email  = trim($_POST["admin_email"]);
  $form_subject = trim($_POST["form_subject"]);

  foreach ( $_POST as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
      <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
      <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
    </tr>
    ";
  }
}
} else if ( $method === 'GET' ) {

  $project_name = trim($_GET["project_name"]);
  $admin_email  = trim($_GET["admin_email"]);
  $form_subject = trim($_GET["form_subject"]);

  foreach ( $_GET as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
      <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
      <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
    </tr>
    ";
  }
}
}

$message = "<table style='width: 100%;'>$message</table>";

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($project_name).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;

mail($admin_email, adopt($form_subject), $message, $headers );

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2018-05-13
@bsloungespa

  1. Use SMTP, for example via lib - PHPMailer

R
Rsa97, 2018-05-13
@Rsa97

To get started, open this letter in gmail and see the reason for getting into spam.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question