• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue php mail function not working after update

I've got the same problem. In my /var/log/mailog/ I have repeated lines about not being able to start Postfix (which the PHP mail() function uses). For example:

Nov 6 21:20:46 vero-solutions postfix/postfix-script[61870]: starting the Postfix mail system
Nov 6 21:20:46 vero-solutions postfix/master[61872]: fatal: open lock file /var/lib/postfix/master.lock: unable to set exclusive lock: Resource temporarily unavailable
Nov 6 21:20:47 vero-solutions postfix/master[61871]: fatal: daemon initialization failure
Nov 6 21:20:48 vero-solutions postfix/postfix-script[61876]: fatal: mail system startup failed

Anyone have any ideas?
 
Thanks IgorG. That has got postfix up and running again, and although I can now send emails from the command line with:

mail -s "test" [email protected] < /dev/null

PHP is still unable to send emails, but doesn't give any errors at all. For example:

<?php
$success = mail("[email protected]", "Subject", "Message", "From: [email protected]");
if (!$success) {
echo "Not sent: Error:" . error_get_last()['message'];
}
?>


just returns "Not sent: Error:" with no error message.

The mail log at /var/log/mailog/ shows nothing at all when the above PHP script is run.

Any ideas?
 
Last edited:
Hi everybody,

finally i can soleve this problem.

the problem is that the default sendmail path is missing after update. this happen to me in centos7

run the command

whereis sendmail

and you have to get something like this:

sendmail: /usr/sbin/sendmail.postfix /usr/sbin/sendmail /usr/lib/sendmail /usr/lib64/sendmail.postfix

if path /usr/sbin/sendmail is not listed, run this command

ln -sf /etc/alternatives/mta /usr/sbin/sendmail

after that you have works phpmail function again.
 
Unfortunately that didn't work for me. The /usr/sbin/sendmail path was already listed in the output of whereis sendmail.

Still unable to send mail via PHP and no error is generated or log created.
 
Could you please post the result of the following commands:
Code:
ls -als /usr/sbin/sendmail
ls -als /etc/alternatives/mta
alternatives --display mta
 
Here are the results:

ls -als /usr/sbin/sendmail

0 lrwxrwxrwx 1 root root 21 Nov 7 20:12 /usr/sbin/sendmail -> /etc/alternatives/mta

ls -als /etc/alternatives/mta
0 lrwxrwxrwx 1 root root 26 Nov 7 20:12 /etc/alternatives/mta -> /usr/sbin/sendmail.postfix

alternatives --display mta
mta - status is auto.
link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix - priority 30
slave mta-pam: /etc/postfix/pam.d/smtp.postfix
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
Current `best' version is /usr/sbin/sendmail.postfix.
 
Please also post the result of:
Code:
ls -als /usr/sbin/sendmail.postfix
ls -als /usr/lib/sendmail.postfix

Anyway, while I don't have a test server handy right now, this should solve your issue (all the lines must be entered one after another before you'll see any response):
Code:
alternatives --install /usr/sbin/sendmail mta /usr/lib64/plesk-9.0/postfix-sendmail-wrapper 90 \
--slave /etc/pam.d/smtp mta-pam /etc/pam.d/smtp.postfix \
--slave /usr/bin/mailq mta-mailq /usr/bin/mailq.postfix \
--slave /usr/bin/newaliases mta-newaliases /usr/bin/newaliases.postfix \
--slave /usr/bin/rmail mta-rmail /usr/bin/rmail.postfix \
--slave /usr/lib/sendmail mta-sendmail /usr/lib/sendmail.postfix \
--slave /usr/share/man/man1/mailq.1.gz mta-mailqman /usr/share/man/man1/mailq.postfix.1.gz \
--slave /usr/share/man/man1/newaliases.1.gz mta-newaliasesman /usr/share/man/man1/newaliases.postfix.1.gz \
--slave /usr/share/man/man5/aliases.5.gz mta-aliasesman /usr/share/man/man5/aliases.postfix.5.gz \
--slave /usr/share/man/man8/sendmail.8.gz mta-sendmailman /usr/share/man/man1/sendmail.postfix.1.gz

Afterwards, run this again to verify the changes:
Code:
alternatives --display mta
 
Thank you. Here is the output of the first two commands.

ls -als /usr/sbin/sendmail.postfix
0 lrwxrwxrwx 1 root root 46 Nov 7 20:12 /usr/sbin/sendmail.postfix -> /usr/lib64/plesk-9.0/sendmail/sendmail.postfix

ls -als /usr/lib/sendmail.postfix
ls: cannot access /usr/lib/sendmail.postfix: No such file or directory

I tried the long multi-line command, and it returned:

link /etc/postfix/pam.d/smtp incorrect for slave mta-pam (/etc/pam.d/smtp mta-pam)

The output of alternatives --display mta was the same as posted above. No changes.
 
I've got another identical server which has updated to Plesk Obsidian, and the PHP mail() function is still working there. For comparison, the output of alternatives --display mta on this working server is:

mta - status is manual.
link currently points to /usr/lib64/plesk-9.0/postfix-sendmail-wrapper
/usr/sbin/sendmail.postfix - priority 30
slave mta-pam: /etc/pam.d/smtp.postfix
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
/usr/lib64/plesk-9.0/postfix-sendmail-wrapper - priority 90
slave mta-pam: /etc/pam.d/smtp.postfix
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib64/plesk-9.0/postfix-sendmail-wrapper
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
Current `best' version is /usr/lib64/plesk-9.0/postfix-sendmail-wrapper.


Does that help at all?
 
UPDATE

I removed the --slave /etc/pam.d/smtp mta-pam /etc/pam.d/smtp.postfix \ line from the multiline command and re-ran it and there was no link message, and the PHP mail() command is now working. The output of alternatives --display mta is now:

mta - status is auto.
link currently points to /usr/lib64/plesk-9.0/postfix-sendmail-wrapper
/usr/sbin/sendmail.postfix - priority 30
slave mta-pam: /etc/postfix/pam.d/smtp.postfix
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
/usr/lib64/plesk-9.0/postfix-sendmail-wrapper - priority 90
slave mta-pam: (null)
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
Current `best' version is /usr/lib64/plesk-9.0/postfix-sendmail-wrapper.


I don't know if that mta-pam line is important and needs fixing, but it's working with it being (null).

Thank you.
 
i have update another server with the same problem. symbolink link of sendmail is missing...

a don´t know what this happen.

I suppose if i rebot the server, i have to create the symlink manually again.

if somebody can help with this!
 
Back
Top