Simplifying WordPress Emails with a Fluent API · vanrossum.dev    

       vanrossum.dev 

 Article

Simplifying WordPress Emails with a Fluent API
==============================================

 ![](https://vanrossum.dev/images/jeffrey-portrait.webp) By Jeffrey van Rossum

  vanrossum.dev  

  [      vanrossum.dev ](https://vanrossum.dev)                      

  [ ← Writing ](https://vanrossum.dev/posts) 

As WordPress developers, we often need to send emails that look polished and professional. But out of the box, the `wp_mail` does not provide that. That’s where my latest package, WP Mail, comes in, a lightweight package designed to make sending good-looking responsive emails in WordPress very easy.

With WP Mail, you can make emails using a clean, fluent API or leverage a view template, whether it's a simple notification or a styled email with buttons and unsubscribe links.

Here’s a quick example of how it works:

```php
use Jeffreyvr\WPMail\Mail;

Mail::make()
    ->to('jane@doe.com')
    ->subject('Hello')
    ->line('Hello there')
    ->button('Click me', 'https://vanrossum.dev')
    ->line('Kind regards, Jeffrey')
    ->send();

```

You can also use a view template with $mail to access the mail object, or add features like CC, BCC, or unsubscribe links with simple methods.

These and the other methods available are listed below:

- `subject(string $subject)` - Set the email subject
- `to(string $email, string $name = '')` - Add recipient
- `cc(string $email, string $name = '')` - Add CC recipient
- `bcc(string $email, string $name = '')` - Add BCC recipient
- `from(string $email, string $name = '')` - Set sender information
- `line(string|callable $text)` - Add a text line to the email
- `button(string $text, string $url)` - Add a call-to-action button
- `view(string $path, array $data = [])` - Use a view template
- `plainText(string|callable $plainText)` - Set the plain text version of the email
- `unsubscribeUrl(string $unsubscribeUrl)` - Set the unsubscribe URL
- `unsubscribeText(string $unsubscribeText)` - Set the unsubscribe text
- `send()` - Send the email

To get started, install via Composer:

```bash
composer require jeffreyvanrossum/wp-mail

```

If you want to execute the sending of emails in a background job, try pairing it with the [wp-job-scheduler](https://github.com/jeffreyvr/wp-job-scheduler) package.

WP Mail is open-source and available on [GitHub](https://github.com/jeffreyvr/wp-mail). If you’re looking to easily send good-looking responsive emails in your WordPress projects, give it a try and let me know your feedback!

  ![](https://vanrossum.dev/images/jeffrey-portrait.webp) Jeffrey van Rossum [@jeffreyrossum](https://x.com/jeffreyrossum) 

 share [𝕏](https://twitter.com/intent/tweet?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fsimplifying-wordpress-emails-with-a-fluent-api&text=Simplifying+WordPress+Emails+with+a+Fluent+API) [WhatsApp](https://wa.me/?text=Simplifying+WordPress+Emails+with+a+Fluent+API+https%3A%2F%2Fvanrossum.dev%2Fposts%2Fsimplifying-wordpress-emails-with-a-fluent-api) [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fsimplifying-wordpress-emails-with-a-fluent-api) 

   © 2026 Jeffrey van Rossum 

  vanrossum.dev vanrossum.dev
