Solved

php doesn't work with linux sendmail utility

Posted on 2014-10-12
8
107 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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 34

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 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