Send emails throught Sendgrid from your WordPress installation using SMTP or API integration.
SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time analytics along with flexible APIs that make custom integration a breeze.
The SendGrid plugin uses SMTP or API integration to send outgoing emails from your WordPress installation. It replaces the wp_mail function included with WordPress.
First, you need to have PHP-curl extension enabled. To send emails through SMTP you need to install also the 'Swift Mailer' plugin.
To have the SendGrid plugin running after you have activated it, go to the plugin's settings page and set the SendGrid credentials, and how your email will be sent - either through SMTP or API.
You can also set default values for the "Name", "Sending Address" and the "Reply Address", so that you don't need to set these headers every time you want to send an email from your application.
You can set the template ID to be used in all your emails on the settings page or you can set it for each email in headers.
Emails are tracked and automatically tagged for statistics within the SendGrid Dashboard. You can also add general tags to every email sent, as well as particular tags based on selected emails defined by your requirements.
There are a couple levels of integration between your WordPress installation and the SendGrid plugin:
How to use
wp_mail() function so all email sends from WordPress should go through SendGrid.
You can send emails using the following function:
wp_mail($to, $subject, $message, $headers = '', $attachments = array())
$to- Array or comma-separated list of email addresses to send message.
$subject- Email subject
$message- Message contents
$headers- Array or "\n" separated list of additional headers. Optional.
$attachments- Array or "\n"/"," separated list of files to attach. Optional.
The wp_mail function is sending text emails as default. If you want to send an email with HTML content you have to set the content type to 'text/html' running
add_filter('wp_mail_content_type', 'set_html_content_type'); function before to
After wp_mail function you need to run the
remove_filter('wp_mail_content_type', 'set_html_content_type'); to remove the 'text/html' filter to avoid conflicts --http://core.trac.wordpress.org/ticket/23578
Example about how to send an HTML email using different headers:
$subject = 'test plugin'; $message = 'testing WordPress plugin'; $to = 'email@example.com, Address2 <firstname.lastname@example.org@>, email@example.com'; or $to = array('firstname.lastname@example.org', 'Address2 <email@example.com>', 'firstname.lastname@example.org'); $headers = array(); $headers = 'From: Me Myself <email@example.com>'; $headers = 'Cc: firstname.lastname@example.org'; $headers = 'Bcc: email@example.com'; $headers = 'unique-args:customer=mycustomer;location=mylocation' $headers = 'categories: category1, category2' $headers = 'template: templateID' $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg'); add_filter('wp_mail_content_type', 'set_html_content_type'); $mail = wp_mail($to, $subject, $message, $headers, $attachments); remove_filter('wp_mail_content_type', 'set_html_content_type');
Requires: 3.3 or higher
Compatible up to: 4.3.3
Last Updated: 2 weeks ago
Active Installs: 10,000+
7 of 13 support threads in the last two months have been marked resolved.
Got something to say? Need help?