PHP使用mail()函数发送邮件流程以及注意事项

1. 配置 php.ini   

sendmail_path = /usr/sbin/sendmail -f yourname@sth.com -t -i

2. 使用函数  

mail($to, $subject, $content, $headers);

3. title乱码如何解决

修改 $subject = "=?UTF-8?B?".base64_encode(标题)."?=";

4. 内容乱码 或者  不以html显示 设置

$headers = 'Content-type: text/html; charset=utf-8' . "
";

 

全部流程如下

        $to =  a@b.com,b@b.com;
        $headers = 'Content-type: text/html; charset=utf-8' . "
"; // 其他 from  之类的head也可以从这里配置
        $subject = "=?UTF-8?B?".base64_encode('测试邮件')."?=";
        mail($to, $subject, $content, $headers);      

5. 特殊的 vim无法编辑utf8内容

需要在vim的初始化文件  ~/.vimrc  中添加两行

set encoding=utf-8
set fileencoding=utf-8
原文地址:https://www.cnblogs.com/sailrancho/p/3834607.html