我将标题传递给mail()函数时无法发送电子邮件

I am trying to send emails with HTML content and whenever i pass headers of any kind the method mail() return false but with no headers i get true .. any clue ?

                $to         = $user->email;
                $name       = $user->first_name.' '.$user->last_name;
                $from       = $this->config->item('admin_email', 'ion_auth');
                $subject    = $this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject');

                $headers = 'MIME-Version: 1.0' . "
";
                $headers .= 'Content-type: text/html; charset=utf-8' . "
";
                $headers .= 'From:  ' . $name . ' <' . $from .'>' . " 
" .
                'Reply-To: '.  $from . "
" .
                'X-Mailer: PHP/' . phpversion();

                $retval = mail ($to,$subject,$message,$headers);

                die(var_dump($retval));

Make sure that variables $name, $from, $to, $subject has the right data and are not empty/null. Your code is functional and should send the email.

If still doesn't work, check the configurations on postfix or what other mail server you're using.

And I suggest to use PhpMailer or SwiftMailer instead of simple mail function.

Try adding a CRLF after your last header. Used to work for me in the olden days.

i.e.,

...
$headers .= 'From:  ' . $name . ' <' . $from .'>' . " 
" .
            'Reply-To: '.  $from . "
" .
            'X-Mailer: PHP/' . phpversion() . "
";
...

Also, the header Content-Type has a capital T. Sometimes, such trivial things may also break it. That's why everyone suggests to move away from it.

That should do it.

Suggestion: Switch to PHPMailer.