Jump to content

Mail php does not work


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.

 

<?php

phpinfo();

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

$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

Results:

 

 

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 [email protected]

// to my local mail server 
date | sendmail -v [email protected]

Results:

 

<[email protected]>: delivery via local: delivered to mailbox

--90D63100B04.1365177950/centos-box.localdomain
Content-Description: Delivery report
Content-Type: message/delivery-status

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

Final-Recipient: rfc822; [email protected]
Action: delivered
Status: 2.0.0
Diagnostic-Code: X-Postfix; delivery via local: delivered to mailbox

--90D63100B04.1365177950/centos-box.localdomain
Content-Description: Message Headers
Content-Type: text/rfc822-headers

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

 


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

Thanks,

jazz....

Link to comment
https://forums.phpfreaks.com/topic/276578-mail-php-does-not-work/
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

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!

 

jazz..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.