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
  • 2
    Php has a mail command that uses sendmail. php.net/manual/en/function.mail.php Commented May 26, 2016 at 14:35
  • It's not clear to me what you need. Commented May 26, 2016 at 14:39

1 Answer 1

0

You can use system

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.