SendGrid
- Contributors: SendGrid
- Donate link: http://sendgrid.com/
- Tags: email, email reliability, email templates, sendgrid, smtp, transactional email, wp_mail,email infrastructure, email marketing, marketing email, deliverability, email deliverability, email delivery, email server, mail server, email integration, cloud email
- Requires at least: 4.6
- Tested up to: 4.9
- Stable tag: 1.11.8
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
Send emails and upload contacts through SendGrid from your WordPress installation using SMTP or API integration.
Description
What is the SendGrid WordPress Plugin?
SendGrid’s cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable deliverability, scalability, and real-time analytics along with flexible APIs that make custom integration with your application a breeze.
SendGrid’s WordPress plugin replaces WordPress’s default wp_mail() function by using either an SMTP or API integration with SendGrid to send outgoing email from your WordPress installation. It also allows you to upload contacts directly to your SendGrid Marketing Campaigns account via a subscription widget.
By using the SendGrid plugin, you will be able to take advantage of improved deliverability and an expanded feature set, including tracking and analytics, to enhance user engagement on your WordPress installation. SendGrid also provides world class customer support, should you run into any issues.
For more details, consult our official documentation
For assistance you can contact SendGrid Support from the SendGrid Support Portal. Click Login & Contact Support, and then Contact Support to see your support contact options. Paying SendGrid customers have the option to contact support via phone, chat, or by submitting a ticket using our web form. All SendGrid customers have the option to submit a ticket using our web form.
Agency Program
Are you sending emails on behalf of your clients? SendGrid's Agency Program offers exclusive pricing and support for agencies looking to improve their email program.
Want to learn more? Visit the SendGrid Agency Page
The Subscription Widget
SendGrid’s WordPress Subscription Widget makes it easy for people visiting your WordPress site to subscribe to your marketing emails, such as any newsletters, announcements, or promotional offers you may send. Upon signup, they’ll automatically receive an opt-in email allowing them to confirm their desire to begin receiving your emails. This confirmation constitutes “double opt-in,” a deliverability best practice.
For more details, consult the official documentation for the Subscription Widget
Multisite
If you are using the SendGrid plugin in a Multisite environment, you need to Network Activate it. You can then access the settings page on the network dashboard and the configure settings will be used for all sites.
You can enable access for SendGrid settings to each subsite in the Multisite Settings tab. If the checkbox is unchecked then that site will not see the SendGrid settings page and it will use the settings set on the network.
Warning! When you activate SendGrid management for a subsite, that site will not be able to send emails until the admin updates the SendGrid settings on that subsite.
If you already had the plugin installed in a Multisite environment and you update to versions after 1.9.0 you may need to reconfigure your plugin.
Installation
Requirements:
- PHP version >= 5.6 and <= 7.1. Installing this plugin on PHP versions 5.3 and earlier will cause your website to break. Installation on PHP versions 5.4 and 5.5 will work but it is not recommended.
- To send emails through SMTP you need to install also the 'Swift Mailer' plugin.
- If wp_mail() function has been declared by another plugin that you have installed, you won't be able to use the SendGrid plugin
To upload the SendGrid Plugin .ZIP file:
- Upload the WordPress SendGrid Plugin to the /wp-contents/plugins/ folder.
- Activate the plugin from the "Plugins" menu in WordPress.
- Create a SendGrid account at http://sendgrid.com/partner/wordpress
- Navigate to "Settings" -> "SendGrid Settings" and enter your SendGrid credentials.
To auto install the SendGrid Plugin from the WordPress admin:
- Navigate to "Plugins" -> "Add New"
- Search for "SendGrid Plugin" and click "Install Now" for the "SendGrid Plugin" listing.
- Activate the plugin from the "Plugins" menu in WordPress, or from the plugin installation screen.
- Create a SendGrid account at http://sendgrid.com/partner/wordpress
- Navigate to "Settings" -> "SendGrid Settings" and enter your SendGrid credentials
For Multisite:
- Navigate to "My Sites" -> "Network Admin" -> "Plugins"
- Click on "Add New"
- Search for "SendGrid Plugin" and click "Install Now" for the "SendGrid Plugin" listing.
- Network Activate the plugin from the "Plugins" menu in WordPress, or from the plugin installation screen.
- Create a SendGrid account at http://sendgrid.com/partner/wordpress
- Navigate to "My Sites" -> "Network Admin" -> "Dashboard"
- Click on the "SendGrid Settings" item in the menu on the left and enter your SendGrid credentials.
Global settings
SendGrid settings can optionally be defined as global variables (wp-config.php):
-
Set the API key. You need to make sure you set the Mail Send permissions to FULL ACCESS, Stats to READ ACCESS and Template Engine to READ or FULL ACCESS when you created the api key on SendGrid side, so you can send emails and see statistics on wordpress):
- API key: define('SENDGRID_API_KEY', 'sendgrid_api_key');
-
Set email related settings:
- Send method ('api' or 'smtp'): define('SENDGRID_SEND_METHOD', 'api');
- From name: define('SENDGRID_FROM_NAME', 'Example Name');
- From email: define('SENDGRID_FROM_EMAIL', 'from_email@example.com');
- Reply to email: define('SENDGRID_REPLY_TO', 'reply_to@example.com');
- Categories: define('SENDGRID_CATEGORIES', 'category_1,category_2');
- Template: define('SENDGRID_TEMPLATE', 'templateID');
- Content-type: define('SENDGRID_CONTENT_TYPE', 'html');
- Unsubscribe Group: define('SENDGRID_UNSUBSCRIBE_GROUP', 'unsubscribeGroupId');
-
Set widget related settings:
- Marketing Campaigns API key: define('SENDGRID_MC_API_KEY', 'sendgrid_mc_api_key');
- Use the same authentication as for sending emails ('true' or 'false'): define('SENDGRID_MC_OPT_USE_TRANSACTIONAL', 'false');
- The contact list ID: define('SENDGRID_MC_LIST_ID', 'listID');
- Display the first and last name fields ('true' or 'false'): define('SENDGRID_MC_OPT_INCL_FNAME_LNAME', 'true');
- First and last name fields are required ('true' or 'false'): define('SENDGRID_MC_OPT_REQ_FNAME_LNAME', 'true');
- Signup confirmation email subject: define('SENDGRID_MC_SIGNUP_EMAIL_SUBJECT', 'Confirm subscription');
- Signup confirmation email content: define('SENDGRID_MC_SIGNUP_EMAIL_CONTENT', '<a href="%confirmation_link%">click here</a>');
- Signup confirmation page ID: define('SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE', 'page_id');
-
Other configuration options:
- Set a custom timeout for API requests to SendGrid in seconds: define('SENDGRID_REQUEST_TIMEOUT', 10);
Filters
Use HTML content type for a single email:
add_filter('wp_mail_content_type', 'set_html_content_type');
// Send the email
remove_filter('wp_mail_content_type', 'set_html_content_type');
Change the email contents for all emails before they are sent:
function change_content( $message, $content_type ) {
if ( 'text/plain' == $content_type ) {
$message = $message . ' will be sent as text ' ;
} else {
$message = $message . ' will be sent as text and HTML ';
}
return $message;
}
add_filter( 'sendgrid_override_template', 'change_content' );
Changing the text content of all emails before they are sent:
function change_sendgrid_text_email( $message ) {
return $message . ' changed by way of text filter ';
}
add_filter( 'sendgrid_mail_text', 'change_sendgrid_text_email' );
Changing the HTML content of all emails before they are sent:
function change_sendgrid_html_email( $message ) {
return $message . ' changed by way of html filter ';
}
add_filter( 'sendgrid_mail_html', 'change_sendgrid_html_email' );
Note that all HTML emails sent through our plugin also contain the HTML body in the text part and that content will pass through the "sendgrid_mail_text" filter as well.
Frequently asked questions
Does SendGrid have an Agency program?
Yes. If you are sending email on behalf of clients you can find more information on SendGrid's Agency page
Is there any official documentation for this plugin ?
Yes. You can find it here
What PHP versions are supported ?
Plugin versions 1.11.x were tested and confirmed to work on PHP 5.4, 5.5, 5.6, 7.0, 7.1. It DOES NOT work on PHP 5.3 and earlier.
Plugin versions 1.10.x were tested and confirmed to work on PHP 5.3, 5.4, 5.5 and 5.6. It DOES NOT work on PHP 7.0 and later.
What credentials do I need to add on settings page ?
Create a SendGrid account at https://sendgrid.com/partner/wordpress and generate a new API key on https://app.sendgrid.com/settings/api_keys.
How can I define a plugin setting to be used for all sites ?
Add it into your wp-config.php file. Example: define('SENDGRID_API_KEY', 'your_api_key');.
How to use SendGrid with WP Better Emails plugin ?
If you have WP Better Emails plugin installed and you want to use the template defined here instead of the SendGrid template you can add the following code in your functions.php file from your theme:
function use_wpbe_template( $message, $content_type ) {
global $wp_better_emails;
if ( 'text/plain' == $content_type ) {
$message = $wp_better_emails->process_email_text( $message );
} else {
$message = $wp_better_emails->process_email_html( $message );
}
return $message;
}
add_filter( 'sendgrid_override_template', 'use_wpbe_template', 10, 2 );
Using the default templates from WP Better Emails will cause all emails to be sent as HTML (i.e. text/html content-type). In order to send emails as plain text (i.e. text/plain content-type) you should remove the HTML Template from WP Better Emails settings page. This is can be done by removing the '%content%' tag from the HTML template.
Why are my emails sent as HTML instead of plain text ?
For a detailed explanation see this page: https://sendgrid.com/docs/Classroom/Build/Format_Content/plain_text_emails_converted_to_html.html
Will contacts from the widget be uploaded to Marketing Campaigns or Legacy Newsletter ?
The contacts will only be uploaded to Marketing Campaigns.
What permissions should my API keys have ?
For the API Key used for sending emails (the General tab):
- Full Access to Mail Send.
- Read Access to Stats.
- Read Access to Supressions > Unsubscribe Groups.
- Read Access to Template Engine.
For the API Key used for contact upload (the Subscription Widget tab):
- Full Access to Marketing Campaigns.
Can I disable the opt-in email?
No. SendGrid’s Email Policy requires all email addressing being sent to by SendGrid customers be confirmed opt-in addresses.
Can I use this plugin with BuddyPress ?
Yes. Our plugin required special integration with BuddyPress and it's regularly tested to ensure it behaves as expected. If you have noticed issues caused by installing this plugin along with BuddyPress, you can add the following line to your wp-config.php to disable it :
define('SENDGRID_DISABLE_BUDDYPRESS', '1');
If you're trying to send plaintext emails using BuddyPress, keep in mind that by default the whitespace content of those emails is normalized.
That means that some newlines might be missing if you expect them to be there.
To disable this functionality, you need to add the following line in your wp-config.php file:
define('SENDGRID_DISABLE_BP_NORMALIZE_WHITESPACE', '1');
Can I use shortcodes to customize the subscription confirmation page ?
Yes. You need to create custom page and select it from the settings page. You can place any of these shortcodes in the body of that page. Here's an example :