gh_mail

πŸ“… Published on

πŸ“ Last updated

Documentation

Β»

Functions

Β»

gh_mail

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

ParameterTypeDescription
$tostring|string[]Recipient email address(es).
$subjectstringEmail subject line.
$messagestringEmail message body.
$headersstring|string[]Additional headers. Default empty.
$attachmentsarrayFile paths to attach. Default empty array.
$mailerobject|nullA 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' ]
    );
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.