N
N
Nikola242018-02-04 18:24:28
Yii
Nikola24, 2018-02-04 18:24:28

Does not send a message to the mail when senders, why?

A very strange bug, if you specify the sender (FROM) from the mail.ru mailbox, it does not send it.
The sending code itself, as I understand it, is standard for yii.

public function sendMail($from, $to, $text, $subject = null, $copy = null)
    {
        $result = array();
        
        if (!preg_match("/^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$/",$from)) {
            return 'Wrong format mail from';
        } elseif (!preg_match("/^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$/",$to)) {
            return 'Wrong format mail to';
        }
        
        $subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
    $headers = "From: $from\r\n";
        
        if ($copy) {
            if (!preg_match("/^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$/",$copy)) {
                return 'Wrong format mail reply';
            } else {
                $headers .= "Bcc: $copy\r\n";
            }
        }
        
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        $headers .= "Content-Transfer-Encoding: base64\r\n"; 
        $text = base64_encode($text);
        
        return mail($to, $subject, $text, $headers);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry, 2018-02-04
@slo_nik

Good evening.
There is a special Mailer class in yii2 that is responsible for sending mail.
Study this class, and throw out your code.

J
John Doe, 2018-02-04
@rabbit418

There is a filter_var function for email validation .

<?php
$email = "[email protected]";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}
?>

O
Oleg, 2018-02-04
@402d

v=spf1 redirect=_spf.mail.ru
and if we look further, we will see that according to the rules for processing letters,
the fact that you sent a direct road to dev/nul
The only way to send on behalf of [email protected]
is through their smtp server by submitting a username/password

D
Dmitry Baskakov, 2018-02-05
@dmitrybascacov

Most likely not so, but let this info be: the mail does not accept letters from its own boxes, but from another server. Those. if the letter was sent from www.site.com by the sender [email protected] to the site mail.ru, then the letter is unlikely to reach, because the mail will swear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question