0
sendmail -s [email protected]
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('[email protected]',"this is title","blablalb","[email protected]") 
   ?>

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" % "[email protected]")
    p.write("To: %s\n" % "[email protected]")
    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
2

1 Answer 1

0

You can use system

$command = '/usr/sbin/sendmail -t -f [email protected] < /email.txt';
system($command);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.