Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

php doesn't work with linux sendmail utility

Posted on 2014-10-12
8
108 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cpanel file manager 8 39
What does this formatting equate to? 7 18
Split wordpress loop 35 56
simple html dom php accessing table/cell  values 4 18
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

791 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