問題列表:
- mail() 函數(shù)使用吕漂;
- 配置 php.ini;
- mail()函數(shù)報(bào)錯(cuò)的解決過程迟几;
使用函數(shù):
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() 函數(shù)報(bào)錯(cuò)
錯(cuò)誤詳情 - sendmail: fatal: parameter inet_interfaces: no local interface found for ::1
解決報(bào)錯(cuò)步驟:
查看centos中的postfix日志
$ more /var/log/maillog
postfix: fatal: parameter inet_interfaces: no local interface found for ::1
$ vi /etc/postfix/main.cf
發(fā)現(xiàn)配置為:
inet_interfaces = localhost
inet_protocols = all
改成:
inet_interfaces = all
inet_protocols = all
重新啟動(dòng)
service postfix start
執(zhí)行重啟,出現(xiàn)報(bào)錯(cuò)
$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 文件.
有兩個(gè) inet_interface匕垫,一個(gè) inet_interfaces = all(這是我打開的)雏门,一個(gè)是 inet_inter_faces = localhost。
注釋 inet_interfaces = localhost 這個(gè)鼎姐,再次重啟就ok了。
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
成功收到郵件的提醒: