我的rpi上有一个使用nginx的网络服务器。我想用php mail()函数发送电子邮件。我安装了postfix和mailutils。 我有以下脚本:
raw_data = read.csv("201511-citibike-tripdata.csv")
unique_id = unique(raw_data$bikeid)
output <- data.frame("bikeid"= integer(0), "end.station.id"= integer(0), "start.station.id" = integer(0), "diff.time" = numeric(0), "stoptime" = character(),"starttime" = character(), stringsAsFactors=FALSE)
for (bikeid in unique_id)
{
onebike <- raw_data[ which(raw_data$bikeid== bikeid), ]
if(nrow(onebike) >=2 ){
for(i in 2:nrow(onebike )) {
if(is.integer(onebike[i-1,"end.station.id"]) & is.integer(onebike[i,"start.station.id"]) &
onebike[i-1,"end.station.id"] != onebike[i,"start.station.id"]){
diff_time <- as.double(difftime(strptime(onebike[i,"starttime"], "%m/%d/%Y %H:%M:%S"),
strptime(onebike[i-1,"stoptime"], "%m/%d/%Y %H:%M:%S")
,units = "mins"))
new_row <- c(bikeid, onebike[i-1,"end.station.id"], onebike[i,"start.station.id"], diff_time, as.character(onebike[i-1,"stoptime"]), as.character(onebike[i,"starttime"]))
output[nrow(output) + 1,] = new_row
}
}
}
}
如果我直接执行它:
<?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>';
}
?>
但如果我在网页中加载脚本,我会获得:
www-data@home ~ $ php -f script.php
<h2>Thank you for your email!</h2>
在/var/log/mail.log中,php -f生成:
<h2>Oops! An error occurred. Try sending your message again.</h2>
但是当我加载页面时:
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
我的一些配置文件: 的/ etc /主机:
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
的/ etc /主机名
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 /邮件名
home
/etc/postfix/main.cf中
home.YYYY
的/ etc / nginx的/位点可用/ mysite的
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
如果是php,postfix,nginx或网络(主机名,域名等)的问题,我无法弄明白。
你能帮助我吗?