Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
56 lines (40 sloc) 1.21 KB

title: Logging all outgoing e-mails

version: 1.0.0

authors: ryan

tags: email, log

problem: Lets say that you want to maintain a log of every email sent from your site.

solution: This can be done quite easily by hooking the WireMail class. Place the following in your /site/ready.php file:

$wire->addHookAfter('WireMail::send', function($event) {
  $mail = $event->object;
    "SENT ($event->return of " . count($mail->to) . "), " .
    "SUBJECT ($mail->subject), " .
    "TO (" .  implode(", ", $mail->to) . "), " .
    "FROM ($mail->from)"

Test things out by sending an email. Here's an example of how I might send a message with the API:

  ->subject('Hello world')
  ->body('How are you doing?')

In your admin, if you go to Setup > Logs > sent-mail, you should see a log entry like this:

SENT (1 of 1), SUBJECT (Hello world), TO (, FROM (