This question has already been answered:

Hello!

I wrote feedback on PHP and everything works fine, but here is one BUT, if you type in the email field β€œtest@gmail.com”, then everything works, but if you enter β€œtest@mail.ru”, then the letter is not sent at all. Mail, where the letter comes from Google.

<form id="application" action="php/send.php" method="POST" name="application "> <input name="name" id="name" maxlength="20" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ вашС имя" required /> <input name="email" type="email" id="email" maxlength="40" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ваш E-mail" required/> <input name="telephone" type="Tel" id="telephone" maxlength="20" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ваш Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½" required /> <button class="FormButton" type="submit" form="application"><i class="fa fa-envelope" aria-hidden="true"></i> ΠŸΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ прайс </button> </form> <?php $sendto = "the.ivan.smirnov@gmail.com"; // ΠΏΠΎΡ‡Ρ‚Π°, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΠΏΡ€ΠΈΡ…ΠΎΠ΄ΠΈΡ‚ письмо $username = $_POST['name']; // Π΄Π°Π½Π½Ρ‹Π΅ ΠΈΠ· поля с Имя $usertel = $_POST['telephone']; // Π΄Π°Π½Π½Ρ‹Π΅ ΠΈΠ· поля Π’Π΅Π»Π΅Ρ„ΠΎΠ½ $usermail = $_POST['email']; // Π΄Π°Π½Π½Ρ‹Π΅ ΠΈΠ· поля Email // Π€ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ° письма $subject = "НовоС сообщСниС"; $headers = "From: " . strip_tags($usermail) . "\r\n"; $headers .= "Reply-To: ". strip_tags($usermail) . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html;charset=utf-8 \r\n"; // Π€ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Ρ‚Π΅Π»Π° письма $msg = "<html><body style='font-family:Arial,sans-serif;'>"; $msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>CΠΎΠΎΠ±Ρ‰Π΅Π½ΠΈΠ΅ с сайта RECO</h2>\r\n"; $msg .= "<p><strong>ΠžΡ‚ ΠΊΠΎΠ³ΠΎ:</strong> ".$username."</p>\r\n"; $msg .= "<p><strong>ΠŸΠΎΡ‡Ρ‚Π°:</strong> ".$usermail."</p>\r\n"; $msg .= "<p><strong>Π’Π΅Π»Π΅Ρ„ΠΎΠ½:</strong> ".$usertel."</p>\r\n"; $msg .= "</body></html>"; // ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ° сообщСния if(@mail($sendto, $subject, $msg, $headers)) { echo "<center><h1>Π‘ΠΎΠΎΠ±Ρ‰Π΅Π½ΠΈΠ΅ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Π½ΠΎ</h1><br><h2>ΠœΡ‹ свяТСмся с Π²Π°ΠΌΠΈ Π² блиТайшСС врСмя! </h2></center>"; } else { echo "<center><img src='img/ne-otprevleno.png'></center>"; } ?> 

Reported as a duplicate by korytoff participants, Alexey Shimansky , Community Spirit ♦ 12 May '17 at 8:01 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Does not go or does not reach? It seems that the Mail.Ru filters just worked. Test on other services - Yandex, Rambler, etc. If the problem is only with Mail.Ru, then see the letter headers (perhaps there is no DKIM, SPF, DMARC and other letter attributes that increase the likelihood of its passing). I also noticed that you suppress the errors of the mail function. What exactly does it give out if you remove error suppression (@)? - Dmitry Maslennikov
  • Did you watch the logs? Which mistakes? - korytoff
  • There are no errors th.890m.com/reco/%233 - Smirnov Ivan
  • This question has been asked / answered many times. The author was just too lazy to look. What is the plus question? - E_p

2 answers 2

Sending mail using SMTP authentication

  // ΠΏΡ€ΠΈΠΌΠ΅Ρ€ использования require_once "SendMailSmtpClass.php"; // ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ класс $mailSMTP = new SendMailSmtpClass('yourmail', 'password', 'ssl://smtp.yandex.ru', 'SenderName', 465); // создаСм экзСмпляр класса // $mailSMTP = new SendMailSmtpClass('Π»ΠΎΠ³ΠΈΠ½', 'ΠΏΠ°Ρ€ΠΎΠ»ΡŒ', 'хост', 'имя отправитСля'); // Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ письма $headers= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; // ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° письма $headers .= "From: example <example@exaample.com>\r\n"; // ΠΎΡ‚ ΠΊΠΎΠ³ΠΎ письмо !!! Ρ‚ΡƒΡ‚ e-mail, Ρ‡Π΅Ρ€Π΅Π· ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ происходит авторизация $result = $mailSMTP->send('to', 'header', ' <h1>Hi ))</h1> ', $headers); // отправляСм письмо 

Download SmtpMailer.php

    At the moment (the year 2017), in general, you will not be able to send a letter with an arbitrary return address from some arbitrary server. You need:

    1. Configure the box from which these letters will come
    2. If this box is on popular email services, then to send a letter you need to use (E) SMTP with authorization
    3. The address that the user specified in the form is simply indicated in the incoming letter