一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Linux系统PHP使用sendmail发送邮件

时间:2015-03-09 编辑:简简单单 来源:一聚教程网

sendmail是在Unix环境下使用最广泛的实现邮件发送/接受的邮件传输代理程序。下面就教大家如何使用sendmail来配合php发邮件

安装sendmail和mailx


yum -y install sendmail mailx

启动


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

当然也要开机自动启动


vim /etc/rc.local

在rc.local后面添加下面代码


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

至此简单的环境就搭建完成了


php采用mail()发送邮件

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

 

 代码如下 复制代码
$from = 'admin@waynerQiu.com';
$to = '78282385@qq.com';
$title = '时间你好123!@#¥%……&*()subject';
$subject = "=?UTF-8?B?".base64_encode($title)."?=";
$body = 'Test link';
$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");
?>

发送后接受到的邮件截图:

Linux系统PHP使用sendmail发送邮件

热门栏目