Solved

php doesn't work with linux sendmail utility

Posted on 2014-10-12
8
109 Views
Last Modified: 2014-10-20
echo '<pre>';

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

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

Open in new window


Why this doesn't work on php?
0
Comment
Question by:Nusrat Nuriyev
  • 4
  • 3
8 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40376212
If it's shared hosting, you won't have permission to run 'system' commands.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40376394
On my Ubuntu 10.04 system, 'sendmail' is in /usr/sbin/sendmail (note the 'sbin').  This works for me.  I commented out your line.

<?php
echo '<pre>';

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

Open in new window

0
 

Author Comment

by:Nusrat Nuriyev
ID: 40376485
Well site hosting in my server.
This does not work as well.

system("/usr/sbin/sendmail -t -i nnuser@gmail.com < /tmp/email.txt", $ret);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Nusrat Nuriyev
ID: 40376489
Hey, do I need to format it in some way?
I mean does email have special format?
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 40376515
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 <me@myplace.com>
MIME-Version: 1.0
To: You <you@yourplace.com>
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

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40376792
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.  http://us3.php.net/manual/en/function.mail.php
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40376802
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.
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 250 total points
ID: 40377117
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.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question