php配置email支持_如何配置使用 php-mail() 函数

本文介绍如何配置PHP的mail()函数以发送邮件,并详细记录了解决mail()函数报错的过程,包括修改php.ini文件及postfix配置,确保邮件发送功能正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题列表:

mail() 函数使用;

配置 php.ini;

mail()函数报错的解决过程;

使用函数:

mail(‘example@qq.com', 'There is a new connect', $connection->getRemoteIp());

配置文件 php.ini

$ php -i

Configure Command => './configure' '--prefix=/usr/local/php7.0.8' '--with-curl' '--with-freetype-dir' '--with-gd' '--with-gettext' '--with-iconv-dir' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir' '--with-mysqli' '--with-openssl' '--with-pcre-regex' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-pear' '--with-png-dir' '--with-xmlrpc' '--with-xsl' '--with-zlib' '--enable-fpm' '--enable-bcmath' '--enable-libxml' '--enable-inline-optimization' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvsem' '--enable-xml' '--enable-zip' '--enable-cli' '--with-mcrypt'

Configuration File (php.ini) Path => /usr/local/php7.0.8/lib

Loaded Configuration File => /usr/local/php7.0.8/lib/php.ini

$ php -i | grep mail

mail.add_x_header => On => On

mail.force_extra_parameters => no value => no value

mail.log => no value => no value

sendmail_from => no value => no value

sendmail_path => /usr/sbin/sendmail -t -i => /usr/sbin/sendmail -t -i

Path to sendmail => /usr/sbin/sendmail -t -i

MAIL => /var/spool/mail/james

$_SERVER['MAIL'] => /var/spool/mail/james

mail() 函数报错

错误详情 - sendmail: fatal: parameter inet_interfaces: no local interface found for ::1

解决报错步骤:

查看centos中的postfix日志

$ more /var/log/maillog

postfix: fatal: parameter inet_interfaces: no local interface found for ::1

$ vi /etc/postfix/main.cf

发现配置为:

inet_interfaces = localhost

inet_protocols = all

改成:

inet_interfaces = all

inet_protocols = all

重新启动

service postfix start

执行重启,出现报错

$sudo service postfix start

Redirecting to /bin/systemctl start postfix.service

Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.

[james@VM_123_128_centos camerawk]$ systemctl status postfix.service

● postfix.service - Postfix Mail Transport Agent

Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Wed 2016-09-07 11:28:33 CST; 35s ago

Process: 921 ExecStart=/usr/sbin/postfix start (code=exited, status=1/FAILURE)

Process: 917 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)

Process: 914 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=75)

再次打开 /etc/postfix/main.cf 文件.

有两个 inet_interface,一个 inet_interfaces = all(这是我打开的),一个是 inet_inter_faces = localhost。

注释 inet_interfaces = localhost 这个,再次重启就ok了。

inet_interfaces = all

#inet_interfaces = $myhostname

#inet_interfaces = $myhostname, localhost

#inet_interfaces = localhost

成功收到邮件的提醒:

Screen Shot 2016-09-07 at 12.04.48 PM.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值