DeX Posted April 20, 2018 Share Posted April 20, 2018 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. Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/ Share on other sites More sharing options...
DeX Posted April 23, 2018 Author Share Posted April 23, 2018 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558016 Share on other sites More sharing options...
requinix Posted April 23, 2018 Share Posted April 23, 2018 First, use sudo to test whether the www-data user really can't send emails. Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558017 Share on other sites More sharing options...
DeX Posted April 23, 2018 Author Share Posted April 23, 2018 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? Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558018 Share on other sites More sharing options...
requinix Posted April 23, 2018 Share Posted April 23, 2018 No, sudo from the command line. Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558019 Share on other sites More sharing options...
DeX Posted April 23, 2018 Author Share Posted April 23, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558020 Share on other sites More sharing options...
requinix Posted April 23, 2018 Share Posted April 23, 2018 No, that will run echo as daemon but mail as bitnami. It would be $ echo "subjectt" | sudo -u daemon mail -s "bodyy" d*****@*****.com Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558021 Share on other sites More sharing options...
DeX Posted April 24, 2018 Author Share Posted April 24, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558026 Share on other sites More sharing options...
Solution DeX Posted April 24, 2018 Author Solution Share Posted April 24, 2018 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. Quote Link to comment https://forums.phpfreaks.com/topic/307186-mail-not-working-in-browser-but-works-fine-from-command-line/#findComment-1558031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.