How to log all outgoing mail on a PHP application

Goal

Log outgoing mail entries to a file on a a PHP application.

Assumptions

You will need:

  • A PHP Application

Problems

I would like to know what mail my PHP application is sending.

Steps

1. Add the following PHP variable to your project.

platform variable:create --name php:sendmail_path --value "/usr/sbin/sendmail -t -X/var/log/app.log"

2. Redeploy your environment and check the /var/log/app.log

tail -f /var/log/app.log

You shoud see entries like

Feb 19 08:00:40 host=249.112.112.1 tls=off auth=off from=XXXX@XXXXX recipients=XXXX@XXXXX mailsize=110 smtpstatus=250 smtpmsg='250 OK' exitcode=EX_OK

Conclusion

I hope this provides some insight to your application and the mails it sends!