當我使用終端發送電子郵件的東西正常工作。我用下面的命令:如何找出PHP和sendmail是否在一起工作?
echo "Subject: test" | /usr/lib/sendmail -v [email protected]
但是當我嘗試這在PHP中:
PHP文件:
<?php bool mail (string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]]) ?>
我的實現:
<?php mail("[email protected]", "my topic", "my message contents", "From: [email protected]"); ?>
,那麼它是不是加工。這是爲什麼?我想它與PHP的php.ini文件有關?
所有我配置:
打開php.ini:
nano /etc/php5/apache2/php.ini
取消註釋sendmail_path寫:
sendmail_path = /usr/sbin/sendmail
取消註釋sendmail_from和寫:
sendmail_from = [email protected]
重啓Apache:
/etc/init.d/apache2 restart
什麼可以如此?爲了更清楚地說明:我希望PHP能夠發送電子郵件!
編輯:
- PHP的mail()函數返回FALSE。
- 爲php.ini中:改變
/usr/sbin/sendmail
成/usr/lib/sendmail
(或反過來)似乎不使對於終端命令的任何差異 - :改變
/usr/sbin/sendmail
成/usr/lib/sendmail
(或反過來)似乎不作任何差異 - 我發送消息給我自己的域和Gmail,都沒有在垃圾郵件文件夾中的郵件。
的Sendmail的日誌文件:
[email protected]:/var/log# cat mail.warn
[email protected]:/var/log# cat mail.err
[email protected]:/var/log# cat mail.log
Mar 20 10:17:09 machine sendmail[12249]: p2K9H2R9012249: from=root, size=0, class=0, nrcpts=1, [email protected]
Mar 20 10:17:20 machine sendmail[12253]: p2K9HImw012253: from=root, size=0, class=0, nrcpts=0, [email protected]
Mar 20 10:17:25 machine sendmail[12255]: p2K9HOAC012255: from=root, size=0, class=0, nrcpts=1, [email protected]
Mar 20 10:20:00 machine sendmail[12277]: p2K9K09k012277: from=root, size=14, class=0, nrcpts=3, msgid=<[email protected]>, [email protected]
Mar 20 10:20:00 machine sm-mta[12279]: p2K9K0Ge012279: <[email protected]>... User unknown
Mar 20 10:20:00 machine sendmail[12277]: p2K9K09k012277: to=-r, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=90014, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Mar 20 10:20:00 machine sm-mta[12279]: p2K9K0Ge012279: from=<[email protected]>, size=290, class=0, nrcpts=2, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar 20 10:20:00 machine sm-mta[12279]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128
Mar 20 10:20:02 machine sm-mta[12279]: p2K9K0Ge012279: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:02, xdelay=00:00:02, mailer=esmtp, pri=60290, relay=gmail-smtp-in.l.google.com. [74.125.77.27], dsn=2.0.0, stat=Sent (OK 1300612802 w59si3196382eeh.92)
Mar 20 10:20:02 machine sm-mta[12279]: STARTTLS=client, relay=aspmx.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128
Mar 20 10:20:04 machine sm-mta[12279]: p2K9K0Ge012279: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:04, xdelay=00:00:02, mailer=esmtp, pri=60290, relay=aspmx.l.google.com. [74.125.79.27], dsn=2.0.0, stat=Sent (OK 1300612804 p50si3196335eei.44)
Mar 20 10:20:04 machine sendmail[12277]: p2K9K09k012277: [email protected],[email protected], ctladdr=root (0/0), delay=00:00:04, xdelay=00:00:04, mailer=relay, pri=90014, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (p2K9K0Ge012279 Message accepted for delivery)
Mar 20 10:20:04 machine sendmail[12277]: p2K9K09k012277: p2K9K09l012277: DSN: User unknown
Mar 20 10:20:04 machine sm-mta[12279]: p2K9K0Gg012279: from=<>, size=1921, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar 20 10:20:05 machine sm-mta[12279]: p2K9K0Gg012279: to=<[email protected]>, delay=00:00:01, xdelay=00:00:01, mailer=local, pri=31921, dsn=2.0.0, stat=Sent
Mar 20 10:20:05 machine sendmail[12277]: p2K9K09l012277: to=root, delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=31038, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (p2K9K0Gg012279 Message accepted for delivery)
Mar 20 10:25:11 machine sendmail[12321]: p2K9PBC3: from=root, size=14, class=0, nrcpts=1, msgid=<[email protected]>, [email protected]
Mar 20 10:25:11 machine sm-mta[12323]: p2K9PBLe: from=<[email protected]>, size=318, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar 20 10:25:11 machine sm-mta[12323]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128
Mar 20 10:25:12 machine sm-mta[12323]: p2K9PBLe: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=30318, relay=gmail-smtp-in.l.google.com. [74.125.77.27], dsn=2.0.0, stat=Sent (OK 1300613112 u12si3204796eeh.99)
Mar 20 10:25:12 machine sendmail[12321]: p2K9PBC3: [email protected], ctladdr=root (0/0), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30014, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (p2K9PBLeMessage accepted for delivery)
Mar 20 11:00:17 machine sendmail[12567]: p2KA0HX9012567: from=root, size=20, class=0, nrcpts=1, msgid=<[email protected]>, [email protected]
Mar 20 11:00:17 machine sm-mta[12568]: p2KA0HNn012568: from=<[email protected]>, size=324, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar 20 11:00:17 machine sm-mta[12568]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128
Mar 20 11:00:18 machine sm-mta[12568]: p2KA0HNn012568: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=30324, relay=gmail-smtp-in.l.google.com. [74.125.77.27], dsn=2.0.0, stat=Sent (OK 1300615218 w59si3268114eeh.65)
Mar 20 11:00:18 machine sendmail[12567]: p2KA0HX9012567: [email protected], ctladdr=root (0/0), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30020, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (p2KA0HNn012568 Message accepted for delivery)
Mar 20 11:16:23 machine sendmail[12675]: p2KAGNg8012675: from=www-data, size=188, class=0, nrcpts=0, msgid=<[email protected]>, [email protected]
[email protected]:/var/log#
EDIT2:
我已經找到了解決方案!
這正是php.ini中的配置,正如我所料。
在php中。INI:
sendmail_path = /usr/sbin/sendmail **-t -i**
現在,讓我們也儘量理解爲什麼,因爲我找到了-t在this site,然後我發現在php.ini文件本身-i。 -t和-i是什麼意思?
-t
從消息標頭中提取收件人。這些被添加到命令行中指定的任何收件人。對於2.1之前的Postfix版本,此選項要求在命令行上未指定收件人地址。
-i
從標準輸入中讀取消息時,請不要僅處理僅包含a的行。字符作爲輸入的結尾。
希望我可以幫助你那些跑了類似的問題。
「它不工作」是不好的信息。你得到什麼錯誤信息?你的日誌裏有什麼? – Mat 2011-03-20 10:03:38
您的終端示例使用'/ usr/lib/sendmail',但您在php中配置了'/ usr/sbin/sendmail'。ini – mario 2011-03-20 10:06:19
第一次完整性檢查:您是否檢查過垃圾郵件文件夾?其次,該方法返回「TRUE」或「FALSE」? 「真」表示「郵件」至少能夠*嘗試*發送電子郵件。 – nitro2k01 2011-03-20 10:06:47