[英]Sending mail via sendmail command line from PHP
sendmail -s me@example.com
Subject:Salem
This is body of email
Ctrl+D
上面的Shell脚本在RHEL-7下可以正常工作 。
现在,我们需要用php包装此命令行( sendmail
),以获得类似以下内容:
<?php
sendmail('from@example.com',"this is title","blablalb","to@example.com")
?>
如何 ? 是否应在RHEL下安装PHP库,以便能够通过PHP在sendmail命令行上中继来发送电子邮件?
众所周知,在Python编程语言的上下文中,同样的问题已经发布,但这是迄今为止的最佳答案 :
def sendMail():
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s\n" % "from@somewhere.com")
p.write("To: %s\n" % "to@somewhereelse.com")
p.write("Subject: thesubject\n")
p.write("\n") # blank line separating headers from body
p.write("body of the mail")
status = p.close()
if status != 0:
print "Sendmail exit status", status
您可以使用系统
$command = '/usr/sbin/sendmail -t -f sender@example.com < /email.txt'; system($command);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.