L
L
lagudal2020-10-05 13:00:18
Email
lagudal, 2020-10-05 13:00:18

Why do messages sent from the site's contact form end up in spam?

Site on vps, if it matters - ubuntu 20.04, hosted by hetzner.
The records seem to be all set up, letters are sent, but most mail servers do not even bring them to users, they kill them immediately and tightly. This is with regard to such monsters as mail.ru, yandex, yahoo, and quite a few more.
Gmail skips, but immediately into spam. Some corporate servers are allowed directly into the inbox, here, as I understand it, how someone set up spam filters.
Previously, the same site was on a shared hosting, the same form and the same send script, everything was delivered normally.
Therefore, I conclude that I configured something incorrectly or did not configure it at all.
Just in case, here is this php script, the simplest one.

php script
<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
 
  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }
  
  //
 mail( "[email protected]", $_POST['subject'], $_POST['message'], "From:" . $_POST['email'] ); 
  //			^
  //  Replace with your email 
}
?>

Here is an example of one log, sending, as the recipient - the address on mail.ru, the sender is taken from the form.
Log
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sendmail[22926]: 0955ZHUO022926: from=www-data, size=131, class=0, nrcpts=1, msgid=<[email protected]>, [email protected]
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sm-mta[22927]: 0955ZHBg022927: from=<[email protected]>, size=368, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost.localdomain [127.0.0.1]
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sendmail[22926]: 0955ZHUO022926: [email protected], ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30131, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (0955ZHBg022927 Message accepted for delivery)
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sm-mta[22929]: STARTTLS=client, relay=emx.mail.ru., version=TLSv1.2, verify=FAIL, cipher=ECDHE-RSA-AES256-GCM-SHA384, bits=256/256
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sm-mta[22929]: 0955ZHBg022927: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120368, relay=emx.mail.ru. [94.100.180.180], dsn=5.0.0, stat=Service unavailable
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sm-mta[22929]: 0955ZHBg022927: 0955ZHBg022929: DSN: Service unavailable
Oct  5 07:35:17 ubuntu-2gb-nbg1-2 sm-mta[22929]: 0955ZHBg022929: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

And here is the output of the script, which is recommended for checking the operation of sendmail.
script
#!/bin/sh
[email protected]
[email protected]
/usr/sbin/sendmail -Am -i -v -f$SENDER -- $RECIPIENT <<END
To: $RECIPIENT
From: $SENDER
Subject: test!

test!
END


conclusion
[email protected] Connecting to emx.mail.ru. via esmtp...
220 emx.mail.ru ESMTP ready 
>>> EHLO localhost.localdomain
250-emx.mail.ru
250-SIZE 73400320
250-8BITMIME
250 STARTTLS
>>> STARTTLS
220 2.0.0 Start TLS
>>> EHLO localhost.localdomain
250-emx.mail.ru
250-SIZE 73400320
250 8BITMIME
>>> MAIL From:<[email protected]> SIZE=87
250 2.0.0 OK
>>> RCPT To:<[email protected]>
250 Go ahead
>>> DATA
354 Go ahead. End your data with <CR><LF>.<CR><LF>
>>> .
550 spam message rejected. Please visit http://help.mail.ru/notspam-support/id?c=GkMfWJupxeT9M078Pmf-JIwSps6sIApqkETr2KO6T0cqAAAAkqAAAEqz0B0~ or  report details to [email protected] Error code: 581F431AE4C5A99BFC4E33FD24FE673ECEA6128C6A0A20ACD8EB4490474FBAA3. ID: 0000002A0000A0921DD0B34A.
[email protected] Connecting to mx00.t-online.de. via esmtp...
554 IP=162.121.221.23 - A problem occurred. (Ask your postmaster for help or to contact [email protected] to clarify.) (BL)
>>> QUIT
[email protected] Connecting to mx03.t-online.de. via esmtp...
[email protected] Closing connection to mx00.t-online.de.
554 IP=162.121.221.23 - A problem occurred. (Ask your postmaster for help or to contact [email protected] to clarify.) (BL)
>>> QUIT
[email protected] Connecting to mx01.t-online.de. via esmtp...
[email protected] Closing connection to mx03.t-online.de.
554 IP=162.121.221.23 - A problem occurred. (Ask your postmaster for help or to contact [email protected] to clarify.) (BL)
>>> QUIT
[email protected] Connecting to mx02.t-online.de. via esmtp...
[email protected] Closing connection to mx01.t-online.de.
554 IP=162.121.221.23 - A problem occurred. (Ask your postmaster for help or to contact [email protected] to clarify.) (BL)
>>> QUIT
MAILER-DAEMON... Saved message in /var/lib/sendmail/dead.letter
Closing connection to mx02.t-online.de.
Closing connection to emx.mail.ru.
>>> QUIT
221 OK, bye

Experimentally, I found out that this test script can be delivered to the inbox, changed the recipient and sender many times, tried different ones.
But even if I hardcode the same sender-receiver in the form script, it's still spam at best...
Where am I missing something?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2020-10-05
@Rsa97

Try sending an email to https://www.mail-tester.com/ and see the result.

D
Dmitry, 2020-10-05
@q2digger

What domain are you sending mail from? from your own?
if so, are DKIM, SPF, etc. configured for the domain?

C
CityCat4, 2020-10-05
@CityCat4

Because apparently they are spam :) You need to send it to mail-tester and see what he says, at least. There are usually several reasons for this:
- the presence (absence) of the necessary headings
- the presence (absence) of the necessary keywords

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question