Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to get the PHP mail() function to work. But it fails to send emails. I run Ubuntu 11.04. I installed sendmail.

I opened the php.ini and set

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = no-reply@mydomain.com

Then I restarted apache.

Then created a simple PHP script to test it but no luck.

When I try to run sendmail it gives me a permissions error, so I have to run 'sudo sendmail'. Does my mail system failure have anything to do with permissions? Is there further configuration I need to do with sendmail?

Thanks.

EDIT: The error is this:

user@server:~$ sendmail
Command 'sendmail' is available in '/usr/sbin/sendmail'
The command could not be located because '/usr/sbin/' is not included in the PATH
environment variable. This is most likely caused by the lack of administrative
privileges associated with your user account.
sendmail: command not found
user@server:~$ sudo sendmail
sendmail: No recipients supplied - mail will not be sent
share|improve this question
    
Depends on the permission problems. Which errors do you get? –  cweiske Jul 19 '11 at 9:26
    
As I mentioned in my answer - if your needs are limited, use ssmtp and also in that case postfix is a huge overkill. But if you wish to learn about mailservers, go on. I have not been so brave, yet :) –  Reinis Jul 19 '11 at 15:37
    
@Jesse Please post your solution as an answer - this isn't a forum, don't edit your question with the solution. –  Marco Ceppi Jul 19 '11 at 15:53
    
No problem. I have to wait 13 hours now. –  Jesse Jul 20 '11 at 13:42
add comment

2 Answers 2

Try adding your user to mail group like this:

sudo adduser yourusername mail

And if you are using PHP with HTTP server (such as Apache), you'll need to do this to:

sudo adduser www-data mail

Apart from the actual question - if your mailing needs are limited to personal/local development - I highly recommend ssmtp.

share|improve this answer
    
So 'www-data' is the apache web user? That's good to know. –  Jesse Jul 19 '11 at 15:29
    
Yes it is on Ubuntu. In other distributions it can be different. For example in Fedora 14 it's user apache. –  Reinis Jul 19 '11 at 15:45
    
Are you certain www-data is the user for Apache2 by default? I just installed Apache2 and it runs as root (which is irrelevant because the webserver isnt internet facing), but I don't think www-data is the user group by default that Apache runs as. –  Thomas W. Jul 20 '11 at 13:54
    
I am pretty sure. For example you need the served files to be owned by www-data group. If they are owned by root, you get 403 in browser. Also, files created by PHP/Apache belong to www-data. At least on my Ubuntu 11.04 :) –  Reinis Jul 20 '11 at 19:21
add comment
up vote 0 down vote accepted

I did this

sudo apt-get install postfix

And now everything is running perfectly. Sendmail apparently isn't the answer. Postfix is.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.