У меня есть веб-сервер на моем RPI с Nginx. Я хотел бы отправлять электронные письма с функцией php mail (). Я установил postfix и mailutils.
У меня есть следующий скрипт:
<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$from = 'From: pi@home';
if (mail($to, $subject, $message, $from)) {
echo '<h2>Thank you for your email!</h2>';
} else {
echo '<h2>Oops! An error occurred. Try sending your message again.</h2>';
}
?>
Если я выполню это напрямую:
www-data@home ~ $ php -f script.php
<h2>Thank you for your email!</h2>
Но если я загружаю скрипт в веб-страницу, я получаю:
<h2>Oops! An error occurred. Try sending your message again.</h2>
В /var/log/mail.log php -f генерирует:
Jan 7 21:34:11 home postfix/pickup[27836]: A0A65A1E5A: uid=1000 from=<www-data>
Jan 7 21:34:11 home postfix/cleanup[27867]: A0A65A1E5A: message-id=<[email protected]>
Jan 7 21:34:11 home postfix/qmgr[27837]: A0A65A1E5A: from=<[email protected]>, size=332, nrcpt=1 (queue active)
Jan 7 21:34:12 home postfix/smtp[27869]: A0A65A1E5A: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[74.125.195.26]:25, delay=1.3, delays=0.07/0.02/0.79/0.44, dsn=2.0.0, status=sent (250 2.0.0 OK 1452198852 y130si13070628wmy.93 - gsmtp)
Jan 7 21:34:12 home postfix/qmgr[27837]: A0A65A1E5A: removed
но когда я загружаю страницу:
Jan 7 20:40:01 home postfix/pickup[25500]: D50C2A1E54: uid=33 from=<www-data>
Jan 7 20:40:01 home postfix/cleanup[25681]: D50C2A1E54: message-id=<[email protected]>
Jan 7 20:40:01 home postfix/qmgr[25501]: D50C2A1E54: from=<[email protected]>, size=601, nrcpt=1 (queue active)
Jan 7 20:40:02 home postfix/smtpd[25684]: connect from home[ZZZZ]
Jan 7 20:40:02 home postfix/smtp[25683]: warning: host home.YYYY[ZZZZ]:25 greeted me with my own hostname home.YYYY
Jan 7 20:40:02 home postfix/smtp[25683]: warning: host home.YYYY[ZZZZ]:25 replied to HELO/EHLO with my own hostname home.YYYY
Jan 7 20:40:02 home postfix/smtp[25683]: D50C2A1E54: to=<[email protected]>, orig_to=<www-data>, relay=home.YYYY[ZZZZ]:25, delay=0.51, delays=0.07/0.04/0.4/0, dsn=5.4.6, status=bounced (mail for home.YYYY loops back to myself)
Jan 7 20:40:02 home postfix/smtpd[25684]: disconnect from home[ZZZZ]
Jan 7 20:40:02 home postfix/cleanup[25681]: 5AF1EA1E56: message-id=<[email protected]>
Jan 7 20:40:02 home postfix/bounce[25688]: D50C2A1E54: sender non-delivery notification: 5AF1EA1E56
Jan 7 20:40:02 home postfix/qmgr[25501]: 5AF1EA1E56: from=<>, size=2524, nrcpt=1 (queue active)
Jan 7 20:40:02 home postfix/qmgr[25501]: D50C2A1E54: removed
Jan 7 20:40:02 home postfix/smtpd[25684]: connect from home[ZZZZ]
Jan 7 20:40:02 home postfix/smtp[25683]: warning: host home.YYYY[ZZZZ]:25 greeted me with my own hostname home.YYYY
Jan 7 20:40:02 home postfix/smtp[25683]: warning: host home.YYYY[ZZZZ]:25 replied to HELO/EHLO with my own hostname home.YYYY
Jan 7 20:40:02 home postfix/smtp[25683]: 5AF1EA1E56: to=<[email protected]>, relay=home.YYYY[ZZZZ]:25, delay=0.18, delays=0.01/0/0.17/0, dsn=5.4.6, status=bounced (mail for home.YYYY loops back to myself)
Jan 7 20:40:02 home postfix/smtpd[25684]: disconnect from home[ZZZZ]
Jan 7 20:40:02 home postfix/qmgr[25501]: 5AF1EA1E56: removed
Некоторые из моих файлов конфигурации:
/ и т.д. / хосты:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ZZZZ home home.YYYY
/ И т.д. / имя хоста
home
/ И т.д. / mailname
home.YYYY
/etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
myhostname = home.YYYY
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
/ И т.д. / Nginx / сайты-доступные / MySite
[...]
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
[...]
Я не могу понять, если это проблема php, postfix, nginx или сети (имена хостов, домены и т. Д.).
Вы можете мне помочь?
Задача ещё не решена.
Других решений пока нет …