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 'user@example.com' /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

ADVERTISEMENTS

Sample PHP Code To Test Your Log File

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

<html>
<head>
<title>nixCraft PHP: Test mail() </title>
</head>
<body>
<?php
$email = "you@example.com";
$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.";
mail($email,$subject,$msg);
?>
</body>
</html>

Run this as:
http://example.com/mailtest.php
And check your server log files as mentioned above.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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

ADVERTISEMENTS
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>, <code>...</code> and <kbd>...</kbd> for code samples.