Jump to content
Sign in to follow this  
DeX

mail() not working in browser but works fine from command line

Recommended Posts

I just set up my first mail server ever using Postfix and when I run 

echo testing | mail -s subjecttttt da***@*********.com

it sends fine and I receive the email at that address. The problem is when I create a php page on the server and write 

mail("da***@*****.com", "test", "test");

then run the page in my browser, it doesn't send the email.

From what I read online, it's because the root user on the command line has permissions to send mail while the www-data user in the browser does not. Is there a way I can specify which user Postfix uses? Any other suggestions? Thanks a lot.

Share this post


Link to post
Share on other sites

Anyone?

Share this post


Link to post
Share on other sites

First, use sudo to test whether the www-data user really can't send emails.

Share this post


Link to post
Share on other sites

First, use sudo to test whether the www-data user really can't send emails.

How can I do that if the command is being run through PHP and Apache?

Share this post


Link to post
Share on other sites

No, sudo from the command line.

Share this post


Link to post
Share on other sites

Is this correct? Daemon is the web user for Bitnami Apache.

bitnami@ip-172-26-***-***:~$ sudo -u daemon echo "subjectt" | mail -s "bodyy" d*****@*****.com

Share this post


Link to post
Share on other sites

No, that will run echo as daemon but mail as bitnami. It would be

$ echo "subjectt" | sudo -u daemon mail -s "bodyy" d*****@*****.com

Share this post


Link to post
Share on other sites

No, that will run echo as daemon but mail as bitnami. It would be

$ echo "subjectt" | sudo -u daemon mail -s "bodyy" d*****@*****.com

 

bitnami@ip-172-26-***.***:~$ echo "subjectt" | sudo -u daemon mail -s "bodyy" d*****@******.com
/home/bitnami/Maildir/sent: Permission denied
Failed to save message in "/home/bitnami/Maildir/sent" - message not sent

Share this post


Link to post
Share on other sites

Never mind. I was trying to run the script on the wrong server, it appears it was working the whole time on the proper server.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.