Plugin Planet

Premium WordPress Plugins

In this tutorial, you will learn how to customize the default opt-in and confirmation email headers for SES Pro. This enables customization of headers such as “From”, “Reply-To”, and “Content-Type”. It also enables you to add custom headers as desired. Note that SES Pro version 1.4 or better is required for this method to work.

Default Functionality

By default, the site administrator’s email address is used for sending both “opt-in” and “sign-up” (aka “confirmation”) emails. This can be overridden via the optin_from and signup_from shortcode attributes. This makes the default SES Pro functionality very flexible, but there are times when you want to override the default methods and specify your own custom email headers. Here is how to do it using SES Pro filter hooks.

Customize Opt-in Headers

The key to customizing the “opt-in” headers is SES Pro’s ses_optin_headers filter hook. With it, we can create a filtering function such as the following, added via custom plugin or your theme’s functions.php file:

function ses_modify_optin_headers($headers) {
	
	$pattern = '/From(.*)<(.*)>/i';
	$replacement = 'From: Site Admin <$2>';
	$headers = preg_replace($pattern, $replacement, $headers);
	
	return $headers;
}
add_filter('ses_optin_headers', 'ses_modify_optin_headers');

This function is hooked into SES Pro via the ses_optin_headers hook, and performs the following tasks:

  • Defines a pattern that matches the “From” header
  • Defines a replacement for the “From” header
  • Uses PHP’s preg_replace() to replace the default “From” header with the new replacement “From” header
  • Returns the modified “From” header to SES Pro

So basically this function enables you to customize the default “From” header for the “opt-in” emails that SES Pro sends when users opt-in. The example here can be used to customize and/or add any headers as desired.

Customize Confirmation Headers

The key to customizing the “confirmation” email headers is SES Pro’s ses_confirm_headers filter hook. With it, we can create a filtering function such as the following, added via custom plugin or your theme’s functions.php file:

function ses_modify_confirm_headers($headers) {
	
	$pattern = '/From(.*)<(.*)>/i';
	$replacement = 'From: Site Admin <$2>';
	$headers = preg_replace($pattern, $replacement, $headers);
	
	return $headers;
}
add_filter('ses_confirm_headers', 'ses_modify_confirm_headers');

This function is hooked into SES Pro via the ses_confirm_headers hook, and performs the following tasks:

  • Defines a pattern that matches the “From” header
  • Defines a replacement for the “From” header
  • Uses PHP’s preg_replace() to replace the default “From” header with the new replacement “From” header
  • Returns the modified “From” header to SES Pro

So basically this function enables you to customize the default “From” header for the “confirmation” emails that SES Pro sends when users opt-in. The example here can be used to customize and/or add any headers as desired.

More Tips

To match other email headers, you can modify the $pattern variable in either of the previous functions. For example, to modify the “Reply-To” header, change the $pattern to the following:

$pattern = '/Reply-To(.*)<(.*)>/i';

For easy reference, here are the default headers that are sent for both optin and confirmation emails:

Headers: X-Mailer: SES Pro
From: email@example.com <email@example.com>
Reply-To: email@example.com <email@example.com>
Content-Type: text/plain; charset="UTF-8"

These headers are designed for simplicity and optimal sending and receiving. Use either of the above techniques to customize as desired.

References & Related