mail() on php
- Mohabot
-
Mohabot
- Member since: May. 2, 2011
- Offline.
-
- Forum Stats
- Supporter
- Level 01
- Art Lover
I'm running CentOS 6.4 on a VPS and have yummed postfix and sendmail. Everything should be working but I just can't get mail() to work on php. I read a few tuts and they only go through some minor tweaks in the config files, which were already set to values specified from the beginning anyway.
I've tried sending mail by issuing a command with sendmail and it seems to be sending mails fine (although they go to junk mail.. not surprised really) but php... no, php just won't send any damn mails.
Anyone that can lead me to success somehow? Help would be appreciated.
- Dean
-
Dean
- Member since: Feb. 16, 2008
- Online!
-
- Send Private Message
- Browse All Posts (10,468)
- Block
-
- Forum Stats
- Moderator
- Level 47
- Gamer
Are you using the mail function correctly? Take a look a the PHP Manual page for the mail function.
$to = 'someone@example.com';
$subject = 'Hello';
$message = 'Can anybody hear me?';
$headers = 'From: me@example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Mail requires a "From:" header, which you set in the additional headers parameter, which in my example is $headers. Alternatively, you can alter the value of "sendmail_from" in your php.ini file which I believe should automatically update the "From:" header for you. I think From is the only additional header that is required.
Was this any help?
BBS + Chat Moderator - Feel free to send me a PM if you have a problem!
Want to instant message me? [ Skype - DeanNewgrounds ]
- Mohabot
-
Mohabot
- Member since: May. 2, 2011
- Offline.
-
- Forum Stats
- Supporter
- Level 01
- Art Lover
At 5/9/13 08:21 AM, Dean wrote: Are you using the mail function correctly? Take a look a the PHP Manual page for the mail function.
$to = 'someone@example.com';
$subject = 'Hello';
$message = 'Can anybody hear me?';
$headers = 'From: me@example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Mail requires a "From:" header, which you set in the additional headers parameter, which in my example is $headers. Alternatively, you can alter the value of "sendmail_from" in your php.ini file which I believe should automatically update the "From:" header for you. I think From is the only additional header that is required.
Was this any help?
I guess, but the main underlying problem was that SELinux was blocking apache from sending mails. Damn tricky thing... I both like and dislike it.
TY for the help :)
- Pilot-Doofy
-
Pilot-Doofy
- Member since: Sep. 13, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (12,142)
- Block
-
- Forum Stats
- Member
- Level 37
- Musician
A lot of hosting companies aren't allowing the basic mail() function anymore, unless you pay for SMTP as well. You could always use SwiftMailer or some other alternative that can use Gmail SMTP to send email, for example.
- Mohabot
-
Mohabot
- Member since: May. 2, 2011
- Offline.
-
- Forum Stats
- Supporter
- Level 01
- Art Lover
At 5/14/13 11:57 PM, Pilot-Doofy wrote: A lot of hosting companies aren't allowing the basic mail() function anymore, unless you pay for SMTP as well. You could always use SwiftMailer or some other alternative that can use Gmail SMTP to send email, for example.
I got it working. My VPS provider ain't no lame so they allow us to use the mail() function ^__^ V
PS. I reply on everything!

