Linux / UNIX: PHP mail() Error Log File

How do I view PHP mail() errors? How do I see php mail() error log file under UNIX or Linux?

Usually, mail log including errors are sent to your systems mail server log directory. If you are using CentOS / RHEL / Redhat or Fedora Linux, check /var/log/maillog file using any one of the following command:
# tail -f /var/log/maillog
# grep '' /var/log/maillog
# more /var/log/maillog

If you are using Ubuntu or Debian Linux, check /var/log/mail.err and /var/log/mail.log files:
# tail -f /var/log/mail.log
# tail -f /var/log/mail.err

Sample PHP Code To Test Your Log File

Create a php code or upload a file called mailtest.php as follows:

<title>nixCraft PHP: Test mail() </title>
$email = "";
$subject = "Happy Birthday!";
$msg = "Wishing you all the great things in life, hope this day will bring you an extra share of all that makes you happiest.";

Run this as:
And check your server log files as mentioned above.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Adam Ziaja Aug 14, 2011 @ 18:46

    or just php script.php

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum