阅读量:4
在 CentOS 系统中,要配置 PHP 以发送邮件,您可以使用命令行工具 sendmail 或安装并配置 postfix
方法一:使用 sendmail
- 安装 sendmail:
sudo yum install sendmail sendmail-cf mailx
- 启动 sendmail 服务:
sudo systemctl start sendmail
sudo systemctl enable sendmail
- 配置 PHP 发送邮件。编辑
/etc/php.ini文件,找到以下行并进行修改:
SMTP = localhost
smtp_port = 25
sendmail_from = your_email@example.com
将 your_email@example.com 替换为您的发件人邮箱地址。
- 重启 web 服务器以使更改生效。如果您使用的是 Apache,请运行:
sudo systemctl restart httpd
如果您使用的是 Nginx 和 PHP-FPM,请运行:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
方法二:使用 postfix
- 安装 postfix:
sudo yum install postfix
- 配置 postfix。编辑
/etc/postfix/main.cf文件,找到以下行并进行修改:
myhostname = your_hostname.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks = 127.0.0.0/8, 192.168.0.0/16
home_mailbox = Maildir/
将 your_hostname.example.com 和 example.com 替换为您的主机名和域名。
- 启动 postfix 服务:
sudo systemctl start postfix
sudo systemctl enable postfix
- 配置 PHP 发送邮件。编辑
/etc/php.ini文件,找到以下行并进行修改:
SMTP = localhost
smtp_port = 25
sendmail_from = your_email@example.com
将 your_email@example.com 替换为您的发件人邮箱地址。
- 重启 web 服务器以使更改生效。如果您使用的是 Apache,请运行:
sudo systemctl restart httpd
如果您使用的是 Nginx 和 PHP-FPM,请运行:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
现在,您应该能够使用 PHP 在 CentOS 系统中发送邮件了。可以使用 PHPMailer 或其他邮件库来简化邮件发送过程。
以上就是关于“centos中php如何配置邮件发送”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm