Hi,
I have a webserver on my rpi with nginx. I would like to send emails with the php mail() function. I installed postfix and mailutils.
I have the following script:
Code:
<?php
$to = 'XXX@gmail.com';
$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>';
}
?>
If I execute it directly:
Code:
pi@home ~ $ php -f script.php
<h2>Thank you for your email!</h2>
But if I load the script in a webpage I obtain:
Code:
<h2>Oops! An error occurred. Try sending your message again.</h2>
In /var/log/mail.log, php -f generates:
Code:
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=<20160107203411.A0A65A1E5A@home.YYYY>
Jan 7 21:34:11 home postfix/qmgr[27837]: A0A65A1E5A: from=<www-data@home.YYYY>, size=332, nrcpt=1 (queue active)
Jan 7 21:34:12 home postfix/smtp[27869]: A0A65A1E5A: to=<XXX@gmail.com>, 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
but when I load a page:
Code:
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=<20160107194001.D50C2A1E54@home.YYYY>
Jan 7 20:40:01 home postfix/qmgr[25501]: D50C2A1E54: from=<www-data@home.YYYY>, 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=<www-data@home.YYYY>, 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=<20160107194002.5AF1EA1E56@home.YYYY>
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=<www-data@home.YYYY>, 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
Some of my configuration files:
/etc/hosts:
Code:
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
/etc/hostname
/etc/mailname
/etc/postfix/main.cf
Code:
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
/etc/nginx/sites-available/mysite
Code:
[...]
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
[...]
I can't figure it out if it is a problem of php, postfix, nginx or networking (hostnames, domains, etc).
Can you help me?