Linux/UNIX:PHP mail()错误日志文件

时间:2020-01-09 10:43:00  来源:igfitidea点击:

如何查看PHP mail()错误?
我如何在UNIX或者Linux下查看php mail()错误日志文件?
通常,包含错误的邮件日志将发送到系统邮件服务器日志目录。
如果您使用的是CentOS/RHEL/Redhat或者Fedora Linux,请使用以下任一命令检查/var/log/maillog文件:

# tail -f /var/log/maillog
# grep '[email protected]' /var/log/maillog
# more /var/log/maillog

如果您使用的是Ubuntu或者Debian Linux,请检查/var/log/mail.err和/var/log/mail.log文件:

# tail -f /var/log/mail.log
# tail -f /var/log/mail.err

示例-PHP代码测试您的日志文件

创建一个php代码或者上传一个名为mailtest.php的文件,如下所示:

<html>
<head>
<title>theitroad PHP: Test mail() </title>
</head>
<body>
<?php
$email = "[email protected]";
$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>

运行为:

http://example.com/mailtest.php

并如上所述检查服务器日志文件。