# Sign Outgoing Emails With DKIM

> Adds a DKIM signature to every email using a private key file and settings stored in wp-config.php, so receiving servers can verify your messages.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, dkim, deliverability, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-dkim-signing/

## Code

```php
add_action( 'phpmailer_init', function ( $phpmailer ) {
    if ( ! defined( 'WPIDE_DKIM_DOMAIN' ) || ! defined( 'WPIDE_DKIM_SELECTOR' ) || ! defined( 'WPIDE_DKIM_PRIVATE_KEY' ) ) {
        return;
    }

    if ( ! is_readable( WPIDE_DKIM_PRIVATE_KEY ) ) {
        return;
    }

    $phpmailer->DKIM_domain   = WPIDE_DKIM_DOMAIN;
    $phpmailer->DKIM_selector = WPIDE_DKIM_SELECTOR;
    $phpmailer->DKIM_private  = WPIDE_DKIM_PRIVATE_KEY;
    $phpmailer->DKIM_identity = $phpmailer->From;

    if ( defined( 'WPIDE_DKIM_PASSPHRASE' ) ) {
        $phpmailer->DKIM_passphrase = WPIDE_DKIM_PASSPHRASE;
    }
} );
```

## Notes

Define WPIDE_DKIM_DOMAIN, WPIDE_DKIM_SELECTOR and WPIDE_DKIM_PRIVATE_KEY (absolute path outside the web root) in wp-config.php and publish the public key in DNS. Does nothing until they are defined.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Sign Outgoing Emails With DKIM" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
