如何配置使用 php-mail() 函數(shù)

問題列表:

  • 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

成功收到郵件的提醒:

Screen Shot 2016-09-07 at 12.04.48 PM.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容