Get log of mail sent with mail() from PHP (sendmail?)

85,564

Solution 1

On Debian-based systems exim logs data in /var/log/exim4/mainlog.

You might find the eximstats tool useful for parsing and culling useful information out of that log file.

Solution 2

sendmail -bp (and mailq) only lists the mail queue: messages queued but not yet sent. It will not include those messages which were delivered successfully.

You should check /var/log/mail.log (and other logfiles) - they almost always have records of every transfer.

Solution 3

php 5.3.0 added 2 settings that makes tracking down rogue scripts easy:

mail.add_x_header
mail.log

http://php.net/manual/en/mail.configuration.php

Share:
85,564

Related videos on Youtube

Kristopher Ives
Author by

Kristopher Ives

My preferred pronoun is God They.

Updated on September 17, 2022

Comments

  • Kristopher Ives
    Kristopher Ives over 1 year

    After some server changes our PHP configuration got nuked, which caused a client's large mailing list to time out partially through about 4,000 addresses or more. We want to avoid sending a duplicate mail as much as possible, and we have the original mailing list.

    The mail was sent using PHP's mail() function, which uses sendmail, which says it's using Exim. I've seen the command:

    sendmail -bp
    

    Which gives me a list of mail that appears was sent. This list isn't very big, and could be accurate (meaning the script timed out after sending only a hundred or so e-mails)

    Is sendmail -bp the best way to get this listing?

    EDIT: I can't find any mail.log file in /var/log/mail.log or via locate mail.log, but WHM seems to have some information on this.

    • Antoine Benkemoun
      Antoine Benkemoun almost 14 years
      What about /var/log/maillog ?
  • yitwail
    yitwail about 11 years
    In centos, and probably RHEL/fedora, it's in /var/log/exim_mainlog