This website requires JavaScript.

架设SendMail使得WordPress可以发送邮件

WordPress建站以后很多事务都需要邮件提醒,比如有人评论,备份是否成功等.本文通过在VPS中安装SendMail服务来实现WordPress的邮件发送.

安装

# 安装SendMail
apt-get install sendmail
# 设置SendMail开始自动运行
apt-get install chkconfig
chkconfig sendmail on
# 修改PHP.INI配置,调用SendMail功能,找到sendmail_path这一行,去掉注释以后改成下面这样
vim /etc/php5/fpm/php.ini
sendmail_path = /usr/sbin/sendmail -t -i

配置

hosts解析

若发现邮件发送非常缓慢,可能是自己hostname没放在hosts解析

# 查看Hostname
hostname
# 编辑hosts文件,设置hostname
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost haseo

修改发送者的域名

修改hosts

127.0.0.1 localhost.localdomain localhost haseo
改为
127.0.0.1 BIHell.com localhost haseo

修改PHP.ini

vim /etc/php5/fpm/php.ini
将sendmail 这行改为
sendmail_path = /usr/sbin/sendmail -f Haseo@BIHell.com -t -i
# 重启PHP服务
service php5-fpm restart

测试

Shell命令行测试

mail -s "test" BIHell.com@outlook.com <con.txt

PHP测试 编写一个PHP文件,然后浏览器访问即可

<?php
$txt = "Why are u so diao!";
$mail = "BIHell@outlook.com";
mail($mail, "My subject", $txt);
echo "message was sent!";
>

参考

4 Best Command-Line Email Clients For Linux

0条评论
avatar