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

Shell script above works fine under RHEL-7 .

We need now to wrap this command line ( sendmail ) with php to get something like :

  <?php 
       sendmail('from@example.com',"this is title","blablalb","to@example.com") 
   ?>

How to ? Is there PHP library should be installed under RHEL to be able to send email by PHP relaying on sendmail commmand line ?


Known that the same question has been posted HOWEVER , in the context of Python programming language , and this is the best answer until now :

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
Community
  • 1
  • 1
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

0

You can use system

$command = '/usr/sbin/sendmail -t -f sender@example.com < /email.txt';
system($command);
Jose Bernalte
  • 177
  • 1
  • 10