从 PHP 通过 sendmail 命令行发送邮件
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 编程语言的上下文中已经发布了相同的问题,并且 the best answer 到现在为止:
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);
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 编程语言的上下文中已经发布了相同的问题,并且 the best answer 到现在为止:
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);