如果你运行了一个 web 服务器或者一台 vps ,你可能需要在你的 php 程序中发送邮件。
sendmail 可以通过你的发行版的软件包管理器安装。
以下是在 centos 7 上安装 sendmail 的说明。
<a target="_blank"></a>
要在 centos 7 中安装 centos 7 ,运行下面的命令:
<code># yum install sendmail</code>
如果在 centos 7 中使用了 selinux, 你需要使用下面的命令允许 sendmail 发送邮件:
<code># setsebool -p httpd_can_sendmail=on</code>
使用这个命令进入 php 交互 shell 中:
<code>php -a</code>
在交互 shell 中,粘贴下面的代码:
<code>mail('[email protected]', "test email", "test email from the internet", null, "-f [email protected]");</code>
不要忘记将 <code>[email protected]</code> 和 <code>[email protected]</code> 分别替换为你的收件地址和发件地址。
要监控邮件日志,你可以使用这个命令:
<code>tail /var/log/maillog</code>
在服务器上安装 sendmail 完成后,你可以允许你的用户通过联系栏通过邮件联系你了。
原文发布时间为:2017-02-28
本文来自云栖社区合作伙伴“linux中国”