安装命令(Ubuntu/Debian):
在终端执行
sudo apt-get update
sudo apt-get install sendmail
sudo systemctl start sendmail
sudo systemctl enable sendmail
配置 php.ini:
记得进行 php.ini 配置
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i
重启服务:
最后重启PHP服务生效
# 重启 PHP-FPM
systemctl restart php8.2-fpm
# 或重启 Apache
systemctl restart apache2
# 或重启 Nginx
systemctl restart nginx
如果登陆的是root用户则按下列步骤安装。
步骤 1:安装 sendmail
打开终端运动下面命令
apt update
apt install -y sendmail sendmail-bin
步骤 2:配置 php.ini
配置 PHP.ini 文件命令
# 找到 php.ini 位置
php -i | grep php.ini
# 编辑 php.ini(根据实际路径)
nano /etc/php/8.2/fpm/php.ini
# 或
nano /etc/php/8.2/apache2/php.ini
或者手动在 PHP.ini 中添加以下配置:
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
步骤 3:重启 PHP 服务
最后重启服务生效
# 重启 PHP-FPM
systemctl restart php8.2-fpm
# 或重启 Apache
systemctl restart apache2
# 或重启 Nginx
systemctl restart nginx