터미널을 사용하여 전자 메일을 보내면 제대로 작동합니다. 나는 다음과 같은 명령을 사용합니다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 ]]) ?>
MY 이행 :
<?php mail("[email protected]", "my topic", "my message contents", "From: [email protected]"); ?>
은, 그것은 아니다 일. 왜 그런가요? PHP php.ini 파일과 관련이 있다고 생각하십니까?
모든 I 구성 :
개방 php.ini 파일 :
nano /etc/php5/apache2/php.ini
주석 sendmail_path 및 쓰기 :
sendmail_path = /usr/sbin/sendmail
주석 sendmail_from을 및 쓰기 :
sendmail_from = [email protected]
다시 시작 아파치 :
/etc/init.d/apache2 restart
어떤 경우가 될 수 있습니까? 이것을 명확하게하기 위해서 : 나는 PHP가 이메일을 보내길 원한다.
편집 :
- PHP의 메일() 함수는 FALSE를 반환합니다. php.ini 파일에 대한
- : 어떤을하지 않는 것
/usr/lib/sendmail
에/usr/sbin/sendmail
을 변경 (또는 그 반대) :/usr/lib/sendmail
에/usr/sbin/sendmail
(또는 그 반대)을 변경하면 터미널 명령에 대한 차이 - 을하지 않는 것 차이점
- 스팸 폴더에 메시지가 없어도 내 도메인과 Gmail 모두에 메일을 보냈습니다. 센드 메일의
로그 파일 :
[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**
, 또한 내가 this site에서 -t를 발견하고 내가 php.ini 파일 자체에 -i를 발견 원인, 이유를 이해하려고 할 수 있습니다. -t와 -i는 무엇을 의미합니까 ??
-t
메일 헤더의 수신자를 추출합니다. 이것은 명령 행에 지정된 모든 수신자에 추가됩니다. 2.1 이전의 Postfix 버전에서는이 옵션을 사용하려면 명령 줄에받는 사람 주소가 지정되어 있지 않아야합니다.
-i
표준 입력에서 메시지를 읽는 경우 a. 문자를 입력의 끝으로 사용합니다. 나는 비슷한 문제에 달렸다 당신의 사람들을 도울 수
희망.
"작동하지 않습니다."좋은 정보가 아닙니다. 어떤 오류 메시지가 나타 납니까? 로그에 뭐가 들었 니? – Mat
터미널 예제는'/ usr/lib/sendmail'을 사용하지만 PHP에서/usr/sbin/sendmail을 설정했습니다.ini – mario
첫 번째 정상 확인 : 스팸 폴더를 확인 했습니까? 둘째, 메소드가'TRUE' 또는'FALSE'를 리턴합니까? 'TRUE'는'mail'이 최소한 전자 메일을 보내려는 시도를 할 수 있음을 의미합니다. – nitro2k01