教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件

在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件

发布时间:2023-05-20   编辑:jiaochengji.com
教程集为您提供在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件等资源,欢迎您收藏本站,我们将为您提供最新的在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件资源

如果你运行了一个 web 服务器或者一台 VPS ,你可能需要在你的 PHP 程序中发送邮件。 Francesco Mondello

本文导航

安装38%

允许服务器可以发送邮件44%

使用 PHP 发送一封测试邮件53%

浏览 sendmail 日志71%

编译自: http://fasterland.net/sendingemailviaphpcentos7usingsendmail.html 作者: Francesco Mondello译者: geekpi

如果你运行了一个 web 服务器或者一台 VPS ,你可能需要在你的 PHP 程序中发送邮件。

同样,如果你正在运行一个 WordPress 博客,或者你正在使用任何类型的 CMS ,你允许你的访问者通过联系表单向你发送电子邮件(例如使用 WordPress 的 Contact Form 7[1] 插件),你可能需要安装一个名为 sendmail[2] 的简单的程序到你的 web 服务器上。

Sendmail 是一个通用的互联网电子邮件投递工具,支持多种邮件传输和传递方法,包括用于通过 Internet 进行电子邮件传输的简单邮件传输协议(SMTP)。来自 Wikipedia[3]。

Sendmail 可以通过你的发行版的软件包管理器安装。

以下是在 CentOS 7 上安装 Sendmail 的说明。

安装

要在 CentOS 7 中安装 CentOS 7 ,运行下面的命令:

# yum install sendmail

允许服务器可以发送邮件

如果在 CentOS 7 中使用了 SELinux, 你需要使用下面的命令允许 sendmail 发送邮件:

# setsebool P httpd_can_sendmail=on

使用 PHP 发送一封测试邮件

使用这个命令进入 php 交互 shell 中:

php a

在交互 shell 中,粘贴下面的代码:

mail('user@receiver.com', "Test email", "Test email from the Internet", null, "f user@sender.com");

不要忘记将 user@receiver.com 和 user@sender.com 分别替换为你的收件地址和发件地址。

浏览 sendmail 日志

要监控邮件日志,你可以使用这个命令:

tail /var/log/maillog

在服务器上安装 sendmail 完成后,你可以允许你的用户通过联系栏通过邮件联系你了。

via: http://fasterland.net/sendingemailviaphpcentos7usingsendmail.html

作者:Francesco Mondello[4] 译者:geekpi 校对:wxy

本文由 LCTT[5] 原创编译,Linux中国 荣誉推出

相关阅读

[1]: Contact Form 7 https://wordpress.org/plugins/contactform7/

[2]: sendmail http://www.sendmail.com/sm/open_source/

[3]: 来自 Wikipedia https://en.wikipedia.org/wiki/Sendmail

[4]: Francesco Mondello http://fasterland.net/

[5]: LCTT https://github.com/LCTT/TranslateProject


您可能感兴趣的文章:
Centos中sendmail发送邮件很慢的解决方法
[PHP] 邮件发送mail()函数失败问题(sendmail命令与postfix )
Mac下使用php的error_log()函数发送邮件
Laravel 基于 SMTP 驱动实现发送邮件
phpmailer发送邮件及实现密码找回功能的代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHP高级特性讨论之邮件相关
用PHP发电子邮件
RHEL4下建立sendmail服务器
asp.net发送邮件的方法汇总

[关闭]
最近更新
浏览排行
~ ~