0

I'm running CentOS7, PHP 8.0.30, postfix 2.10.1-9.el7 Sometimes emails we try to send through php mail() function are not sent and after enabling verbose logging for postfix's pickup, cleanup, qmgr, smtp we noticed nothing is being pickup.

pickup unix n - n 60 1 pickup -v

The email is lost between mail() (which call is logged in syslog) and postfix.

Sendmail is correctly defined in php.ini

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

Our exact same code runs perfectly on another server from the pool, but not this one server in particular. Any idea ?

6
  • 1
    Test that you can send an email with /usr/sbin/sendmail manually from command line. Commented Jul 29, 2024 at 20:31
  • Look at the mails which fail, how they are constructed in your PHP code relative to the ones which succeed. If you're doing anything funky with the additional headers, that may be preventing the mail from being created properly. Look at the PHP log to see if any errors are generated where the failing mails are being created. Commented Jul 29, 2024 at 22:41
  • I'm able to manually send mails, and when it works it's going through the exact one liner mail() code. Commented Aug 5, 2024 at 14:16
  • What does your webserver logs show? Commented Aug 5, 2024 at 14:41
  • 1
    You could run script with mail() function under strace and see what's going on. Commented Aug 6, 2024 at 15:59

2 Answers 2

3
+50

Here are some troubleshooting steps -

  1. Check Syslog for PHP Mail:

    • Ensure that the mail() function is logging correctly in the syslog.
  2. Verify sendmail_path:

    • Double-check sendmail_path in php.ini:
      sendmail_path = /usr/sbin/sendmail -t -i 
  3. Compare Configurations:

    • Compare PHP, Postfix, and server configurations between the working and non-working servers to identify discrepancies.
  4. Permissions:

    • Ensure the user running PHP has permissions to execute /usr/sbin/sendmail.
  5. Postfix Logs:

    • Enable and check verbose logging for Postfix components:
      pickup -v cleanup -v qmgr -v smtp -v 
  6. Check Mail Queue:

    • Use mailq to inspect if mails are stuck in the queue.
  7. SELinux/AppArmor:

    • Ensure SELinux or AppArmor is not restricting the sendmail execution.
  8. Firewall/Network:

    • Ensure there are no firewall rules or network issues preventing email sending.
  9. Restart Services:

    • Restart Postfix and PHP-FPM/Apache to ensure configuration changes take effect:
      systemctl restart postfix systemctl restart php-fpm 
  10. Test Direct Sendmail:

    • Try sending a test email directly using sendmail:
      echo "Subject: Test" | /usr/sbin/sendmail -v [email protected] 

By systematically checking these areas, you should be able to identify and resolve the issue.

3
  • "Ensure that the mail() function is logging correctly in the syslog." - Do you mean the mail log service? PHP's mail() function does not write to logs. Commented Aug 6, 2024 at 14:44
  • the Mail Queue step with mailq is a very good point which often gives valuable insights. Commented Aug 8, 2024 at 5:07
  • Thank you for trying and the effort ! (and maybe chatGPT that already gave us the same hints to check). Everything looked good on those points. Commented Aug 9, 2024 at 14:10
0

Turned out by disabling (what looks like absolutely unrelated) a grpc option, the issue stopped happening.

/etc/php.d/40-grpc.ini #grpc.enable_fork_support = 1 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.