Jump to content

Mail php does not work

Go to solution Solved by jazzman1,

Recommended Posts

Hey folks,

yesterday I decided to upgrade my CentOS machine from 6.3 to 6.4 and now my php mail function stoped to work.

What I've tested so far:

1. If I try to send a message to my remote mail server I've got a false result.




if ( function_exists( 'mail' ) )
    echo 'mail() is available' . '<br />';
    echo 'mail() has been disabled'.'<br />';

$to = 'myEmail@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: jazzman@centos-box.localdomain' . "\r\n" .
    'Reply-To: jazzman@centos-box.localdomain' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)) {
 echo "mail send ... OK"; 
} else {
echo "mail send ... ERROR!";




mail() is available

mail send ... ERROR!



2. I checked the path to the default mail client - sendmail and it is correct:


sendmail_path:        /usr/sbin/sendmail -t -i


3. Then I try to send a message to my remote server through a BASH script and the sendmail works fine:


// to my remote mail server
date | sendmail -v myEmail@gmail.com

// to my local mail server 
date | sendmail -v jazzman@centos-box.localdomain



<jazzman@centos-box.localdomain>: delivery via local: delivered to mailbox

Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; centos-box.localdomain
X-Postfix-Queue-ID: 90D63100B04
X-Postfix-Sender: rfc822; jazzman@centos-box.localdomain
Arrival-Date: Fri,  5 Apr 2013 12:05:50 -0400 (EDT)

Final-Recipient: rfc822; jazzman@centos-box.localdomain
Action: delivered
Status: 2.0.0
Diagnostic-Code: X-Postfix; delivery via local: delivered to mailbox

Content-Description: Message Headers
Content-Type: text/rfc822-headers

Return-Path: <jazzman@centos-box.localdomain>
Received: by centos-box.localdomain (Postfix, from userid 500)
    id 90D63100B04; Fri,  5 Apr 2013 12:05:50 -0400 (EDT)
Message-Id: <20130405160550.90D63100B04@centos-box.localdomain>
Date: Fri,  5 Apr 2013 12:05:50 -0400 (EDT)
From: jazzman@centos-box.localdomain (jazzman)
To: undisclosed-recipients:;


For some reason the mail function does not work to me!



Edited by jazzman1
Link to comment
Share on other sites

No, the error_reporting shows nothing.


I think that it's a server security issue and coming from selinux in centos.


Let me check in the error's log in the server, something happened here.


Apr  5 12:07:21 centos-box postfix/sendmail[4899]: fatal: chdir /var/spool/postfix: Permission denied

Edited by jazzman1
Link to comment
Share on other sites

I found a solution without disabling SELinux.


Here is it:


[root@centos-box jazzman]# /usr/sbin/getsebool httpd_can_sendmail
httpd_can_sendmail --> off

[root@centos-box jazzman]# setsebool -P httpd_can_sendmail 1

[root@centos-box jazzman]# /usr/sbin/getsebool httpd_can_sendmail

httpd_can_sendmail --> on

Hope this helps someone!



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.