LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cant get php mail() to send email (https://www.linuxquestions.org/questions/linux-newbie-8/cant-get-php-mail-to-send-email-4175453347/)

ostrosky.jeremiah 03-08-2013 10:07 PM

Cant get php mail() to send email
 
I'm not exactly 'new' to Linux but here's where I'm at. I recently upgraded the server in my house to Centos 6.3, 64bit (from Windoze) and it's taken a bit of getting used to. Basically the machine is used for a handful of purposes, including storing backups for all of my machines but more importantly it serves up my website. I'm using Apache 2.2 and PHP 5.3 (same setup I had on windows). I use a php script "FormToEmail" so users can submit requests via my website and they are sent to my gmail account (main email for that specific purpose). On the previous windows install, I used a simple program called Free SMTP Server. My question is, what is the easiest way for me to setup an outgoing only mail server just to handle the php script and deliver messages input into the html form. I've read some on ssmtp but can't seem to get it working. Suggestions anyone? I'd like to keep it as simple as possible as all it has to accomplish is to send the form information (which is gathered by the php script) to a single address, which is the same every single time.

shivaa 03-08-2013 11:27 PM

Welcome to LQ!

Check this out here.

ostrosky.jeremiah 03-09-2013 12:59 AM

I've installed Postfix and configured it using this tutorial: http://www.unixmen.com/activate-and-...ntos-and-rhel/ and can successfully send emails from the command line using something like this: echo "test email" | mail myemailaddress@gmail.com I've also set (in the php.ini file) sendmail=/usr/sbin/sendmail -t -i and 'sendmail' is a symlink that points to /usr/sbin/sendmail.postfix, yet it appears the emails are still not being delivered via the web form. Again, they are successfully delivered when testing via the command line, but not when sent through the web form. Here is a link to the php FormToEmail that I'm using (and I've used before on other sites, hosted elsewhere).

http://formtoemail.com/FormToEmail.txt (text file of the actual code, I'm using it as-is, but of course with my email address, etc inserted (same php file I used when hosting the site on windows machine, so I know it's not faulty)

Any thoughts?

ostrosky.jeremiah 03-09-2013 01:19 AM

Ok, I think I'm making progress but not sure where to go from here. However, this is what's appearing in /var/log/maillog:

Mar 9 02:13:13 centos postfix/sendmail[10243]: fatal: chdir /var/spool/postfix: Permission denied

ostrosky.jeremiah 03-09-2013 01:27 AM

AWESOME. I figured it out with some help from our good friend Google, and a lot of reading. Turns out (as I'm very new to using SELINUX) that is was actually selinux preventing apache from sending the emails. I simply set 'setsebool -P httpd_can_sendmail 1' and VOILA! All is well and I'm now receiving emails from the web form. Can't believe it took me so long to realize the issue but like I said, this is the first distro I've used that uses selinux so... lesson learned, and mental note taken :)


All times are GMT -5. The time now is 11:04 PM.