问题列表:
- 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
成功收到邮件的提醒: