0
sendmail -s me@example.com
Subject:Salem
This is body of email
Ctrl+D

上面的 Shell 脚本在 RHEL-7 下运行良好。

我们现在需要sendmail用 php 包装这个命令行 () 以获得类似:

  <?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
4

1 回答 1

0

你可以使用系统

$command = '/usr/sbin/sendmail -t -f sender@example.com < /email.txt';
system($command);

于 2016-05-26T14:36:21.420 回答