PHP mail()函数不发送电子邮件

我正在尝试使用mail()PHP函数发送电子邮件.我一直工作,直到我试图给它一个用户注册”的主题,然后邮件没有发送!

继承人的代码(大大简化了)

$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'From: noreply@example.com' . "\r\n" ;
$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
$headers .= 'From: Website <admin@example.com>';
mail($to, 'User Registration', $message, $headers);

我还尝试使用包含文本字符串但不起作用的变量.

为什么在添加主题例外时不发送邮件

谢谢

编辑:更新的代码仍然无法正常工作

$to = $this->post_data['register-email'];
$message = 'Hello etc';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: Website <admin@example.com>';
mail($to, 'User Registration', $message, $headers);

解决方法:

在你的第4行,你正在使用’处理它内部的所有内容作为字符串,所以改变

$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';

至:

$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

并且正如评论中提到的那样,将chareset更改为charset

编辑:

如果您根据documentation发送txt / html邮件,也在标题中设置mime,那么试试这个

    $to = $this->post_data['register-email'];
    $message = 'Hello etc';

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= 'From: Website <admin@example.com>' . "\r\n";
    mail($to, 'User Registration', $message, $headers);

如果它仍然无效,您可以尝试调试代码,只需添加即可

error_reporting(E_ALL);
ini_set('display_errors', '1');

页面顶部,并从那里拿走它,如果你仍然无法解决它自己发布在这里,我会尽我所能帮助你.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...