首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从PHP通过sendmail命令行发送邮件

从PHP通过sendmail命令行发送邮件
EN

Stack Overflow用户
提问于 2016-05-26 14:29:21
回答 1查看 1K关注 0票数 0
代码语言:javascript
复制
sendmail -s me@example.com
Subject:Salem
This is body of email
Ctrl+D

之上的Shell脚本在RHEL-7下工作良好的

我们现在需要用php包装这个命令行( sendmail ),以获得如下内容:

代码语言:javascript
复制
  <?php 
       sendmail('from@example.com',"this is title","blablalb","to@example.com") 
   ?>

怎么做?是否应该在RHEL下安装PHP库,以便能够通过PHP在sendmail通信线路上中继发送电子邮件?

但是,在programming语言的上下文中,已经发布了相同的问题,这就是the best answer,直到现在:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-26 14:36:21

你可以使用系统

代码语言:javascript
复制
$command = '/usr/sbin/sendmail -t -f sender@example.com < /email.txt';
system($command);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37463772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档