php doesn't work with linux sendmail utility

echo '<pre>';

system("/usr/bin/sendmail -t -i < /tmp/email.txt", $ret);

// Printing additional info
echo '
<hr />Last line of the output: '

Open in new window

Why this doesn't work on php?
Nusrat NuriyevAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
If it's shared hosting, you won't have permission to run 'system' commands.
Dave BaldwinFixer of ProblemsCommented:
On my Ubuntu 10.04 system, 'sendmail' is in /usr/sbin/sendmail (note the 'sbin').  This works for me.  I commented out your line.

echo '<pre>';

//system("/usr/bin/sendmail -t -i < /tmp/email.txt", $ret);
system("/usr/sbin/sendmail -t -i < emailtext.txt", $ret);
// Printing additional info
echo "$ret
<hr />Last line of the output: ";

Open in new window

Nusrat NuriyevAuthor Commented:
Well site hosting in my server.
This does not work as well.

system("/usr/sbin/sendmail -t -i < /tmp/email.txt", $ret);
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Nusrat NuriyevAuthor Commented:
Hey, do I need to format it in some way?
I mean does email have special format?
Dave BaldwinFixer of ProblemsCommented:
Yes it does.  I looked at the source for a small email and copied it for my text file.  You may need to use a valid local email address to send from.  This is about the smallest set of headers you can get away with.  Less and your email might be considered spam.
From: Me <>
MIME-Version: 1.0
To: You <>
Subject: Sendmail email text test
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dave Baldwin said:
Note the blank line after the headers.

Open in new window

Dave BaldwinFixer of ProblemsCommented:
By the way, what you are doing is almost exactly what the PHP mail() function does.  It takes the information, formats it, and passes it on to 'sendmail' just like you are doing.
Nusrat NuriyevAuthor Commented:
we can do it with php mail() function, but it does not work as a `sendmail` system() call.
However system call for `ls` works fine.
1. If you can do an "ls" via a system/shell call, but not another command, then it is likely a permissions issue. In the most common setup with Apache and PHP, your PHP script will run as the same user as Apache, and usually Apache is locked down for security reasons and uses the nearly-permisionless users like "nobody".

2. If you want to allow Apache/PHP to execute sendmail (or any other specific application), usually the best way is through sudo (which temporarily elevates permissions in Linux in a specific situation), or through another permissions-changing module like suPHP. There are many, but most of them are a little tough to set up if you're not used to sysadmin work.

3. Usually if you want the PHP mail() command to make use of the sendmail binary, you need to uncomment and set the value of sendmail_path in your php.ini file and restart the web server.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.