Linux配置sendmail实现PHP发送邮件

Linux配置sendmail实现PHP发送邮件

1.安装sendmail

yum -y install sendmail

2.安装mail命令

yum -y install mailx

3.开启sendmail

/etc/rc.d/init.d/sendmail start

4.设置开机启动

vim /etc/rc.local

最后一行添加上:

/etc/rc.d/init.d/sendmail start

5.这时写1个简单mail函数已经可以发送邮件:

mail(“接受方email“,”邮件主题”,”正文内容”,”from:发送方email”);

但是还存在以下问题:

1.邮件标题、内容中文乱码

2.邮件内容不支持html

 

6.优化

$from = '发送方email';
$to = '接受方email';
$title = '时间你好123!@#¥%……&*()subject';
$subject = "=?UTF-8?B?".base64_encode($title)."?="; //解决标题中文乱码
$body = '<a href="http://www.baidu.com" target="_blank">link</a>';
// 实现邮件内容支持html
$headers[] = "From: $from";
$headers[] = "X-Mailer: PHP";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf8";
$headers[] = "Reply-To: $from"; 
mail($to, $subject, $body, implode("\r\n", $headers), "-f $from");


直接在php.ini中修改,

[html]  view plain copy
  1. sendmail_path = /usr/sbin/sendmail -f admin@aizher.com -t -i  


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值