[Documentation](https://groundhogg.io/documentation/) » [Classes](https://groundhogg.io/documentation/#doc-classes)

# \Groundhogg\Email

Published Tuesday, June 9, 2026 · Last updated Tuesday, June 9, 2026

extends `Base_Object_With_Meta`

Represents an email template stored in Groundhogg. This is not a record of a sent message — it is the reusable template that gets merged and dispatched when a funnel step or broadcast runs. Instantiate it with an email ID to access its content, settings, and send it manually.

## Methods

| Method | Returns | Description |
| --- | --- | --- |
| `get_subject_line()` | `string` | Returns the raw subject line (may contain merge tags). |
| `get_merged_subject_line()` | `string` | Returns the subject line with merge tags replaced for the current contact. |
| `get_title()` | `string` | Returns the internal admin title of the email. |
| `get_pre_header()` | `string` | Returns the pre-header text shown in email client previews. |
| `get_content()` | `string` | Returns the raw email body content (block JSON or HTML). |
| `get_alt_body()` | `string` | Returns the plain-text alternative body. |
| `get_from_user()` | `WP_User\|false` | Returns the WordPress user set as the from address. |
| `get_status()` | `string` | Returns the email status: `'draft'`, `'ready'`, or `'archived'`. |
| `is_draft()` | `bool` | Returns `true` if the email is in draft status. |
| `is_ready()` | `bool` | Returns `true` if the email is ready to send. |
| `is_transactional()` | `bool` | Returns `true` if the email is flagged as transactional (bypasses marketability check). |
| `is_marketing()` | `bool` | Returns `true` if the email is a marketing email. |
| `is_confirmation_email()` | `bool` | Returns `true` if the email is an opt-in confirmation email. |
| `get_template()` | `string` | Returns the template slug used to render the email (e.g. `'boxed'`, `'full-width'`). |
| `get_css()` | `string` | Returns the compiled inline CSS for the email. |
| `get_alignment()` | `string` | Returns the email content alignment (`'left'` or `'center'`). |
| `get_width()` | `int` | Returns the email template width in pixels. |
| `get_contact()` | `Contact\|false` | Returns the contact currently set as the recipient (used during send/merge). |
| `get_event()` | `Event\|false` | Returns the event currently associated with this send. |
| `get_click_tracking_link( $url )` | `string` | Wraps a URL in a click-tracking redirect link. |
| `get_open_tracking_src()` | `string` | Returns the URL of the open-tracking pixel. |
| `send( $contact_id_or_email, $event = null )` | `bool\|WP_Error` | Sends the email to a contact immediately. Returns `true` on success, `false` or `WP_Error` on failure. |
| `enable_test_mode()` | `void` | Puts the email into test mode so it sends regardless of the contact’s marketability. |
| `build()` | `string` | Renders and returns the full HTML email string ready for sending. |

## Usage

Here’s a pseudo code example for a hypothetical transactional email integration.

```

<?php

add_action( 'my_plugin_appointment_confirmed', 'my_plugin_send_confirmation_email', 10, 2 );

/**
 * Send a personalised confirmation email when an appointment is booked.
 *
 * @param int    $email_id
 * @param string $contact_email
 *
 * @return void
 */
function my_plugin_send_confirmation_email( $email_id, $contact_email ) {

    $email   = new \Groundhogg\Email( $email_id );
    $contact = \Groundhogg\get_contactdata( $contact_email );

    if ( ! $email->exists() || ! $contact ) {
        return;
    }

    // Send transactional emails regardless of opt-in status
    if ( ! $email->is_transactional() ) {
        $email->enable_test_mode();
    }

    $result = $email->send( $contact );

    if ( is_wp_error( $result ) ) {
        my_plugin_log_error( $result->get_error_message() );
    }
}
```
