#### A Small Helper Function

This is the helper function that we've defined in order to help us easily retrieve the post title associated with the given comment. We've abstracted it into a helper function so that we can use it later in the plugin.

The helper function is simple:

Clear, right? Get a reference to the comment object by the specified ID, then return the title of the post that's associated with the given comment's post ID.

At this point, feel free to test your code. Assuming that you followed the steps in the first article, you should have a development environment setup that's sending emails to your inbox.

Activate the plugin, leave a comment on the post and you should see a new subject line.

Neat, huh?

### The Email Text

Next, we're ready to begin actually setting the email text. In our plugin, let's have the email include the folllowing:

• An area for the content that reads "The original contents of this email read:" after which we'll include the original comments
• A simple footer that denotes if this is a normal comment or a trackback or pingback, and that includes the comment author's email address.

We'll also provide some styling to demonstrate how we can easily customize the look and feel of an email.

So locate the email_text function and include the following:

Though the code comments should be relatively clear, note that we're doing the following:

• Retrieving the comment
• Setting up a header for the email (where we also retrieve the post title using our helper function)
• Writing out the original code comment
• Defining a footer that shows the type of comment and the comment author

Note also that we've written some inline styles. I'm assuming that you'll be using Gmail as your mail client when testing these emails; however, every email client handles styles differently so be sure to review this chart if you end up doing this in some of your production-ready projects.

Once done, trigger another email and you should see something like the following:

Oops! That's not what we want. Luckily, this is an easy fix and it requires one more line of code in the plugin.

In order to send styled, HTML-based messages using WordPress, we need to set the headers of the email properly. To do this, update the email_headers function to look like this:

This informs the email client to render the content as HTML. Permitting that you've done this right, you should see something like the following:

Much better!

## Conclusion

Obviously, we've only scratched the surface of just how powerful customizing your WordPress-based emails can be especially if you take the time to generate some nice markup, elaborate styles, and so on.

In my opinion, the most important thing to understand is how to hook into the filters that are provided that allow us to do all of the above.

Hopefully, this series has provided enough information to get your started. Remember to check out the plugin on GitHub, and good luck with those custom emails!