PHP mail() not working

Hello Experts,

I'm running a new CentOS 6.4 installation and am having problems getting the php mail() function to work on the new server.  Can anyone help guide me to checking the ports and the php.ini configuration (I'm new at this so there's no guarantee I didn't blow it somewhere) as well as seeing if php is accessing sendmail and verifying if sendmail is working properly?

Thanks!
LVL 17
OmniUnlimitedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Does any email client work on your server?  They would all use 'sendmail' or a sub like Postfix.
0
remeshkCommented:
Could you please post the below command output to check further.

# netstat -lntp | grep 25

# alternatives --display mta

# php -v
0
OmniUnlimitedAuthor Commented:
Thank you experts for your kind assistance.

@DaveBaldwin:  Roundcube does work, although JIRA does not.  The system does use Postfix.

@remeshk: Here you go:

# netstat -lntp | grep 25
tcp        0      0 xx.xx.xx.xx:80              0.0.0.0:*                   LISTEN      xxx65/nginx
tcp        0      0 xx.xx.xx.xx:53              0.0.0.0:*                   LISTEN      xxx40/named
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      xxx41/master
tcp        0      0 xx.xx.xx.xx:443             0.0.0.0:*                   LISTEN      xxx65/nginx
tcp        0      0 :::25                       :::*                        LISTEN      xxx41/master
# alternatives --display mta
mta - status is manual.
 link currently points to /usr/lib64/plesk-9.0/psa-sendmail
/usr/lib64/plesk-9.0/psa-sendmail - priority 90
Current `best' version is /usr/lib64/plesk-9.0/psa-sendmail.
# php -v
PHP 5.3.3 (cli) (built: Jul 12 2013 20:35:47)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

arnoldCommented:
ls -l /usr/sbin/sendmail
look in the php.ini whether it is looking at /usr/sbin/sendmail for sendmail_path

look at /var/log/maillog

lsof -i:25
0
OmniUnlimitedAuthor Commented:
Thank you arnold for your assist.  Here is the requested information:

ls -l /usr/sbin/sendmail

lrwxrwxrwx 1 root root 21 Sep 17 13:37 /usr/sbin/sendmail -> /etc/alternatives/mta

Here are the php.ini settings:

[mail function]
; For Win32 only.
; http://www.php.net/manual/en/mail.configuration.php#ini.smtp
SMTP = mail.example.com
; http://www.php.net/manual/en/mail.configuration.php#ini.smtp-port
smtp_port = 25

; For Win32 only.
; http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-from
sendmail_from = noreply@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i

Open in new window


maillog is empty.

lsof -i:25
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
master  xxx41 root   12u  IPv4 xxxxx64      0t0  TCP *:smtp (LISTEN)
master  xxx41 root   13u  IPv6 xxxxx66      0t0  TCP *:smtp (LISTEN)
0
arnoldCommented:
ls -l /etc/alternatives/mta

Trying to find where your /usr/sbin/sendmail is pointing.
0
OmniUnlimitedAuthor Commented:
lrwxrwxrwx 1 root root 33 Sep 17 13:37 /etc/alternatives/mta -> /usr/lib64/plesk-9.0/psa-sendmail
0
arnoldCommented:
Look in the plesk control panel where the mail logs are and see what they are reporting

tail -f /usr/local/psa/var/log/maillog

If you have the option of switching the Mail server from sendmail to something else, it might be simpler to manage IMHO.


http://kb.parallels.com/en/5801
0
OmniUnlimitedAuthor Commented:
Um, forgive my ignorance, but I don't see any mail logs in plesk?

Here is the (sanitized) information:

Sep 26 22:08:25 xx-xx-xx-xx postfix/anvil[13834]: statistics: max cache size 1 at Sep 26 22:05:04
Sep 26 22:11:13 xx-xx-xx-xx postfix/smtpd[13878]: connect from 114-32-207-47.HINET-IP.hinet.net[114.32.207.47]
Sep 26 22:11:13 xx-xx-xx-xx postfix/smtpd[13878]: NOQUEUE: reject: RCPT from 114-32-207-47.HINET-IP.hinet.net[114.32.207.47]: 554 5.7.1 <superedm002@yahoo.com.hk>: Relay access denied; from=<0546@msa.hinet.net> to=<superedm002@yahoo.com.hk> proto=SMTP helo=<xx.xx.xx.xx>
Sep 26 22:11:14 xx-xx-xx-xx postfix/smtpd[13878]: lost connection after RCPT from 114-32-207-47.HINET-IP.hinet.net[114.32.207.47]
Sep 26 22:11:14 xx-xx-xx-xx postfix/smtpd[13878]: disconnect from 114-32-207-47.HINET-IP.hinet.net[114.32.207.47]
Sep 26 22:11:14 xx-xx-xx-xx /usr/lib64/plesk-9.0/psa-pc-remote[15202]: Message aborted.
Sep 26 22:11:14 xx-xx-xx-xx /usr/lib64/plesk-9.0/psa-pc-remote[15202]: Message aborted.
Sep 26 22:14:34 xx-xx-xx-xx postfix/anvil[13880]: statistics: max connection rate 1/60s for (smtp:114.32.207.47) at Sep 26 22:11:13
Sep 26 22:14:34 xx-xx-xx-xx postfix/anvil[13880]: statistics: max connection count 1 for (smtp:114.32.207.47) at Sep 26 22:11:13
Sep 26 22:14:34 xx-xx-xx-xx postfix/anvil[13880]: statistics: max cache size 1 at Sep 26 22:11:13
Sep 26 23:12:23 xx-xx-xx-xx postfix/qmgr[18643]: CDA11138052D: from=<xxx@localhost.localdomain>, size=725, nrcpt=1 (queue active)
Sep 26 23:12:23 xx-xx-xx-xx postfix/smtp[14366]: connect to mail.example.com[xx.xx.xx.xx]:25: Connection refused
Sep 26 23:12:23 xx-xx-xx-xx postfix/smtp[14366]: CDA11138052D: to=<sam@example.com>, relay=none, delay=97184, delays=97184/0.01/0.31/0, dsn=4.4.1, status=deferred (connect to mail.example.com[xx.xx.xx.xx]:25: Connection refused)

Open in new window


I did mention we are using postfix?  I'd prefer to keep it that way if at all possible.

Thanks again.
0
arnoldCommented:
Your problem is that the enter of any email is xxx@localhost.localdomain that it will be rejected.

Add in php.ini -fyouremailaddress to the line where sendmail_path before the -t option.

Your other problem is I. /etc/php.ini you have options that only apply to windows based PHP configuration.
Comment out the SMTP and the SMTP_port and mail_from

Mail() should use the local MTA.
0
OmniUnlimitedAuthor Commented:
Hi arnold,

I'm not sure I understand your statement:

Your problem is that the enter of any email is xxx@localhost.localdomain that it will be rejected.

Here is the modified php.ini file:

[mail function]
; For Win32 only.
; http://www.php.net/manual/en/mail.configuration.php#ini.smtp
;SMTP = mail.example.com
; http://www.php.net/manual/en/mail.configuration.php#ini.smtp-port
;smtp_port = 25

; For Win32 only.
; http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-from
;sendmail_from = noreply@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-path
sendmail_path = /usr/sbin/sendmail -f noreply@example.com -t -i

Open in new window


Is this correct?

How do I ensure that mail() uses the local MTA?
0
arnoldCommented:
The -fnoreply@example.com no space between the option and the address.

The sendmail_path is what tells mail() function what to do.

Try sending a few emails. And look at the log.

Note the prior entry the reference to mail.example.com port 25 connection refused is why your prior attempts did not work.
0
OmniUnlimitedAuthor Commented:
OK, I removed the space as you said and tried sending an email.

tail -f /usr/local/psa/var/log/maillog

Sep 27 00:01:15 xx-xx-xx-xx postfix/qmgr[18643]: 3FBA41380531: from=<xxx@localhost.localdomain>, size=948, nrcpt=1 (queue active)
Sep 27 00:01:16 xx-xx-xx-xx postfix/smtp[14714]: certificate verification failed for mail.othersite.com[xx.xx.xx.xx]:25: self-signed certificate
Sep 27 00:01:16 xx-xx-xx-xx postfix/smtp[14714]: 3FBA41380531: to=<joe@othersite.com>, relay=mail.othersite.com[xx.xx.xx.xx]:25, delay=1.2, delays=0.09/0.01/0.94/0.14, dsn=5.0.0, status=bounced (host mail.othersite.com[xx.xx.xx.xx] said: 550-Verification failed for <xxx@localhost.localdomain> 550-Unrouteable address 550 Sender verify failed (in reply to RCPT TO command))
Sep 27 00:01:16 xx-xx-xx-xx postfix/cleanup[14711]: 6940D1380532: message-id=<20130927070116.6940D1380532@localhost.localdomain>
Sep 27 00:01:16 xx-xx-xx-xx postfix/bounce[14716]: 3FBA41380531: sender non-delivery notification: 6940D1380532
Sep 27 00:01:16 xx-xx-xx-xx postfix/qmgr[18643]: 6940D1380532: from=<>, size=3099, nrcpt=1 (queue active)
Sep 27 00:01:16 xx-xx-xx-xx postfix/trivial-rewrite[14712]: warning: do not list domain localhost.localdomain in BOTH mydestination and virtual_alias_domains
Sep 27 00:01:16 xx-xx-xx-xx postfix/qmgr[18643]: 3FBA41380531: removed
Sep 27 00:01:16 xx-xx-xx-xx postfix/local[14717]: 6940D1380532: to=<xxx@localhost.localdomain>, relay=local, delay=0.08, delays=0.03/0.01/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
Sep 27 00:01:16 xx-xx-xx-xx postfix/qmgr[18643]: 6940D1380532: removed

Open in new window


I tried to send an email to another site's email address (othersite.com).  It looks like I might be having issues there too?
0
arnoldCommented:
Modify php.ini
Replace the sendmail_path with

sendmail_path=/usr/sbin/sendmail -oi -fnoreply@yourdomin.com -t

Double check your setup within php page that calls mail that you have a full/functional email defined in the from.

The issue is that if you only use xxx, your mail server will add the domain which is currently localhost.localdomain.  Localhost.localdomain is not. Valid host and many mail server will reject an email from an invalid email address.

You could configure postfix to identify itself as mail.yourdomain.com and to append yourdomain.com to a sender that is not a complete email address.
0
OmniUnlimitedAuthor Commented:
I went ahead and changed the sendmail_path per your instructions.

Here is part of the code from the php page:

$parm = "From: Example.com <noreply@example.com>\r\n" .
	"Reply-To: admin@example.com\r\n" .
	"Return-Path: admin@example.com\r\n" .
	"MIME-Version: 1.0\n" . 
	"Content-type: text/html; charset=iso-8859-1"; 
mail("joe@othersite.com", "Message From Example.com", stripslashes($msg), $parm);

Open in new window


tail -f /usr/local/psa/var/log/maillog

Sep 27 00:25:03 xx-xx-xx-xx postfix/qmgr[18643]: 23DDB1380531: from=<xxx@localhost.localdomain>, size=948, nrcpt=1 (queue active)
Sep 27 00:25:04 xx-xx-xx-xx postfix/smtp[14867]: certificate verification failed for mail.othersite.com[xx.xx.xx.xx]:25: self-signed certificate
Sep 27 00:25:05 xx-xx-xx-xx postfix/smtp[14867]: 23DDB1380531: to=<joe@othersite.com>, relay=mail.othersite.com[xx.xx.xx.xx]:25, delay=2, delays=0.09/0.01/1.8/0.11, dsn=5.0.0, status=bounced (host mail.othersite.com[xx.xx.xx.xx] said: 550-Verification failed for <xxx@localhost.localdomain> 550-Unrouteable address 550 Sender verify failed (in reply to RCPT TO command))
Sep 27 00:25:05 xx-xx-xx-xx postfix/cleanup[14864]: 28D301380532: message-id=<20130927072505.28D301380532@localhost.localdomain>
Sep 27 00:25:05 xx-xx-xx-xx postfix/bounce[14869]: 23DDB1380531: sender non-delivery notification: 28D301380532
Sep 27 00:25:05 xx-xx-xx-xx postfix/qmgr[18643]: 28D301380532: from=<>, size=3099, nrcpt=1 (queue active)
Sep 27 00:25:05 xx-xx-xx-xx postfix/trivial-rewrite[14865]: warning: do not list domain localhost.localdomain in BOTH mydestination and virtual_alias_domains
Sep 27 00:25:05 xx-xx-xx-xx postfix/qmgr[18643]: 23DDB1380531: removed
Sep 27 00:25:05 xx-xx-xx-xx postfix/local[14870]: 28D301380532: to=<xxx@localhost.localdomain>, relay=local, delay=0.07, delays=0.03/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to mailbox)
Sep 27 00:25:05 xx-xx-xx-xx postfix/qmgr[18643]: 28D301380532: removed

Open in new window


Am I not using complete addresses?
0
arnoldCommented:
Run file /usr/lib64/plesk/psa-sendmail

If it returns saying it is a script that is where it might be stripping.  To fix, make sure your hostname is a fully qualified domain,
Run hostname
Do you have /etc/postfix? Or is it within the /usr/local/psa/etc/postfix.
0
arnoldCommented:
Try the following within the shell
echo "To: recipient@domain.com
From: sender@domain.com
Subject: test

Message body.
" |/usr/sbin/sendmail -oi -fsender@domain.com -t

Then post the maillog.
The psa-sendmail might be .....
0
OmniUnlimitedAuthor Commented:
There was no file /usr/lib64/plesk/psa-sendmail, so I ran /usr/lib64/plesk-9.0/psa-sendmail.  It appears to be stuck.

I have a couple of questions for you:

1. How to I check to see if the hostname is a fully qualified domain name?
2. How do I run hostname?

Postfix is in the etc directory.
0
arnoldCommented:
file Is a command.
which file
file looks at the entry to its right and reports the type of file it is, text, linked, command, etc.
0
arnoldCommented:
More /etc/hosts
/bin/hostname
Within /etc/postfix/main.cf you can set what the mailserver will identify itself as.
0
OmniUnlimitedAuthor Commented:
I went ahead and typed what you told me into the shell.

Here is the maillog:

Sep 27 01:09:55 xx-xx-xx-xx postfix/pickup[15020]: 2CDD31380532: uid=0 from=<noreply@example.com>
Sep 27 01:09:55 xx-xx-xx-xx postfix/cleanup[15255]: 2CDD31380532: message-id=<20130927080955.2CDD31380532@localhost.localdomain>
Sep 27 01:09:55 xx-xx-xx-xx postfix/qmgr[18643]: 2CDD31380532: from=<noreply@example.com>, size=356, nrcpt=1 (queue active)
Sep 27 01:09:55 xx-xx-xx-xx postfix/smtp[15257]: certificate verification failed for mail.othersite.com[xx.xx.xx.xx]:25: self-signed certificate
Sep 27 01:09:57 xx-xx-xx-xx postfix/smtp[15257]: 2CDD31380532: to=<joe@othersite.com>, relay=mail.othersite.com[xx.xx.xx.xx]:25, delay=1.9, delays=0.08/0.01/0.75/1.1, dsn=2.0.0, status=sent (250 OK id=1VPT7f-0001n6-N9)
Sep 27 01:09:57 xx-xx-xx-xx postfix/qmgr[18643]: 2CDD31380532: removed

Open in new window

0
OmniUnlimitedAuthor Commented:
LOL!  Well, that shows my ignorance.  I didn't even know file was a command.

Here is the output:

file /usr/lib64/plesk-9.0/psa-sendmail

/usr/lib64/plesk-9.0/psa-sendmail: setuid ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

Open in new window


more /etc/hosts

127.0.0.1       localhost.localdomain   localhost        localhost localhost.loc
aldomain localhost4 localhost4.localdomain4
::1     localhost.localdomain   localhost        localhost localhost.localdomain
 localhost6 localhost6.localdomain6

Open in new window


/bin/hostname

localhost.localdomain

Open in new window


With regards to /etc/postfix/main.cf, are you talking about "myhostname" which is showing localhost.localdomain?

Oh, hey, and I just now received the email you had me set up through the shell!!!
0
OmniUnlimitedAuthor Commented:
Hello, are you still with me?  I still am not receiving emails through php mail().
0
arnoldCommented:
Yes, change myhostname in /etc/postfix/main.cf to yourdomain.com and restart postfix service postfix restart
Or
service postfix stop
service postfix start
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OmniUnlimitedAuthor Commented:
WOOHOO!!!!!!!

arnold, you definitely ARE a genius!!!!  Thank you, thank you, thank you for all your patience, hard work and assistance.  I couldn't have resolved this issue without you.
0
OmniUnlimitedAuthor Commented:
Hey arnold, I don't know if you are monitoring this question or not, but if you are, I sure could use your help.  I am trying to set up JIRA email on the same server and am having similar problems as to when I had problems with PHP.

You can see the question here:

http://www.experts-exchange.com/OS/Linux/Q_28254216.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.