N
N
nagge1012019-05-04 23:56:05
PHP
nagge101, 2019-05-04 23:56:05

Why does an email sent using a php script end up in spam?

Hello. Please help.
I have a script that is written in php and when accessing it from js via ajax, it sends a message to the mail, but the message itself gets into spam, why?
Here is the php code itself:

<?php
$method = $_SERVER['REQUEST_METHOD'];
$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 );

And here is the ajax call itself:
$("#call").submit(function() {
        var th = $(this);
        $.ajax({
            type: "POST",
            url: "mail.php",
            data: th.serialize()
        }).done(function() {
            alert("Заявка отправлена! Скоро мы с вами свяжемся.");
            setTimeout(function() {
                th.trigger("reset");
            }, 1000);
        });
        return false;
    });

Checked ip in spam databases, missing. How to be?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
E
Evgeny Samsonov, 2019-05-05
@bitniks

The problems may be different. You can check letters for spam using this service
https://www.mail-tester.com
It will check the letter and give you a list of problems and tips on how to fix them

A
aleks-th, 2019-05-05
@aleks-th

In a nutshell, you can't say.
Firstly, Google, mail and Yandex react to the contents of the letter, it is enough to send a letter with the same content to many clients and getting into spam is guaranteed.
Secondly, there are many parameters taken into account except for ip.
For example a PTR record is desirable. Without it, you'll end up in spam faster.
Then mailers fire whether users put a daw spam, if the user has put you in spam, then this text is already more suspicious.
--
Here is a person who wrote in sufficient detail about mailings
https://habr.com/ru/company/mailru/blog/419591/
---
Well, or as a simple option, send through an account in the same Yandex using their server, chances are that block less.

A
Alexander, 2019-05-05
@AleksandrB

Many mails do not accept the mail function at all due to security reasons, you can set any names and email of the sender in it and mislead users. If you want mail to go to the main folder, use phpmailer .

V
vanyamba-electronics, 2019-05-06
@vanyamba-electronics

Spam is there because.

A
Alex-1917, 2019-05-05
@alex-1917

They googled it on the Toaster, 29 times the issue was already raised and 6 times it was successfully chewed and resolved!

B
bios06, 2019-05-05
@bios06

Went through the smtp protocol. It is possible through Google or Yandex. True, there are limitations.

S
Stanislav, 2019-05-05
@lamo4ok

The code you are using sends emails without authorization on any of the mail servers. Unless you have configured sending with authorization by ip. In order for your emails to be trusted, you need a lot of things if you want to set up your own mail server, and only one if you will be doing authorization on some already configured public one. In this case, the domain can be in the sender's address, either yours or, if it doesn't matter, this public server. A lot has been written about setting up your domain on Yandex or somewhere else. As a result, you need a script that will be able to authorize via SMTP. We have already talked about the standard in such things, phpmailer. Find examples of its use, and that's it.

G
GSV4, 2022-01-26
@GSV4

It is necessary to register on your mail server:
- SPF-record;
- DKIM record;
- DMARC-record (optional, but desirable).
For details see here:
https://help.mail.ru/postmaster/technical-settings...
(Setting up SPF, DKIM, DMARC)
or here:
https://sendpulse.com/ru/knowledge-base/email- serv...
(How to set up email authentication)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question