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

# gh_mail

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

Groundhogg’s low-level mail-sending function. Works like WordPress’s `wp_mail()` but routes the message through the Groundhogg email service configured in settings (MailHawk, SendGrid, SES, etc.). Use this when you want Groundhogg’s deliverability infrastructure to handle a message but don’t need the full email template, merge tag, or funnel tracking pipeline.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `$to` | `string\|string[]` | Recipient email address(es). |
| `$subject` | `string` | Email subject line. |
| `$message` | `string` | Email message body. |
| `$headers` | `string\|string[]` | Additional headers. Default empty. |
| `$attachments` | `array` | File paths to attach. Default empty array. |
| `$mailer` | `object\|null` | A specific mailer instance to use. Default `null` uses the configured service. |

## Return value

`bool` — `true` if the email was sent successfully.

## Usage

```

\Groundhogg\gh_mail(
    'jane@example.com',
    'Your receipt',
    '
Thanks for your purchase!

',
    [ 'Content-Type: text/html; charset=UTF-8' ]
);
```

## Example

Here’s a pseudo code example for a hypothetical admin alert integration.

```

add_action( 'my_plugin_critical_event', 'my_plugin_send_owner_alert' );

/**
 * Send an alert to the primary Groundhogg owner through the configured email service.
 *
 * @param string $message
 *
 * @return void
 */
function my_plugin_send_owner_alert( $message ) {

    $owner = \Groundhogg\get_primary_owner();

    if ( ! $owner ) {
        return;
    }

    \Groundhogg\gh_mail(
        $owner->user_email,
        '[My Plugin] Alert',
        '
' . wp_kses_post( $message ) . '

',
        [ 'Content-Type: text/html; charset=UTF-8' ]
    );
}
```
