Replacement wp_mail()
to use Sendgrid API.
Add your default configuration to maybe wp-config.php by adding the constants described below.
define( 'TWENTYSIXB_SENDGRID_API_KEY', '<YOUR_API_KEY>' );
define( 'TWENTYSIXB_SENDGRID_FROM_EMAIL', '[email protected]' );
define( 'TWENTYSIXB_SENDGRID_FROM_NAME', 'Your name' );
Define a template by replacing <YOUR_TEMPLATE_ID>
with a template of your choice and or a category.
add_filter(
'twentysixb_sendgrid_mail',
function( $email ) {
$email->setTemplateId( '<YOUR_TEMPLATE_ID>' );
$email->addCategory( 'website' );
return $email;
}
);
Define the values for the variables in your template.
add_filter(
'twentysixb_sendgrid_template_data',
function( $data ) {
$data['cta_text'] = 'Subscribe CTA';
$data['cta_url'] = 'https://awesome.newsletter.com';
return $data;
}
);
Configuration hook to define the template ID that is used.
add_filter(
'twentysixb_sendgrid_mail',
function( $email ) {
$email->setTemplateId( '<YOUR_TEMPLATE_ID>' );
$email->addCategory( 'website' );
return $email;
}
);