SendGrid - Version 1.8.0

Version Description

  • Added SendGrid\Email() for $header
  • Fix Send Test form not being displayed issue
Download this release

Release Info

Developer team-rs
Plugin Icon 128x128 SendGrid
Version 1.8.0
Comparing to
See all releases

Code changes from version 1.7.6 to 1.8.0

lib/class-sendgrid-settings.php CHANGED
@@ -118,12 +118,20 @@ class Sendgrid_Settings {
118
  $status = 'error';
119
  }
120
 
121
- if ( 'apikey' == $auth_method and ! empty( $api_key ) and ! Sendgrid_Tools::check_api_key( $api_key, true ) ) {
 
122
  $message = 'API Key is invalid or without permissions.';
123
  $status = 'error';
124
- } elseif ( 'credentials' == $auth_method and ! empty( $user ) and ! empty( $password ) and ! Sendgrid_Tools::check_username_password( $user, $password, true ) ) {
 
 
 
 
125
  $message = 'Username and password are invalid.';
126
  $status = 'error';
 
 
 
127
  }
128
 
129
  if ( $template and ! Sendgrid_Tools::check_template( $template ) ) {
118
  $status = 'error';
119
  }
120
 
121
+ if ( 'apikey' == $auth_method and ! empty( $api_key ) ) {
122
+ if ( ! Sendgrid_Tools::check_api_key( $api_key, true ) ) {
123
  $message = 'API Key is invalid or without permissions.';
124
  $status = 'error';
125
+ } else {
126
+ $status = 'valid_auth';
127
+ }
128
+ } elseif ( 'credentials' == $auth_method and ! empty( $user ) and ! empty( $password ) ) {
129
+ if ( ! Sendgrid_Tools::check_username_password( $user, $password, true ) ) {
130
  $message = 'Username and password are invalid.';
131
  $status = 'error';
132
+ } else {
133
+ $status = 'valid_auth';
134
+ }
135
  }
136
 
137
  if ( $template and ! Sendgrid_Tools::check_template( $template ) ) {
lib/sendgrid/sendgrid-wp-mail.php CHANGED
@@ -38,12 +38,24 @@ require_once plugin_dir_path( __FILE__ ) . 'class-sendgrid-php.php';
38
  */
39
  function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() )
40
  {
41
- $mail = new SendGrid\Email();
 
 
 
42
 
43
- $method = Sendgrid_Tools::get_send_method();
44
 
45
- // Compact the input, apply the filters, and extract them back out
46
- extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
 
 
 
 
 
 
 
 
 
47
 
48
  // prepare attachments
49
  $attached_files = array();
@@ -75,133 +87,153 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
75
  $cc = array();
76
  $bcc = array();
77
  $unique_args = array();
78
- if ( empty( $headers ) ) {
79
- $headers = array();
80
- } else {
81
- if ( ! is_array( $headers ) ) {
82
- // Explode the headers out, so this function can take both
83
- // string headers and an array of headers.
84
- $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
85
  } else {
86
- $tempheaders = $headers;
87
- }
88
- $headers = array();
89
-
90
- // If it's actually got contents
91
- if ( ! empty( $tempheaders ) ) {
92
- // Iterate through the raw headers
93
- foreach ( (array) $tempheaders as $header ) {
94
- if ( false === strpos( $header, ':' ) ) {
95
- if ( false !== stripos( $header, 'boundary=' ) ) {
96
- $parts = preg_split( '/boundary=/i', trim( $header ) );
97
- $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
98
- }
99
- continue;
100
- }
101
- // Explode them out
102
- list( $name, $content ) = explode( ':', trim( $header ), 2 );
103
-
104
- // Cleanup crew
105
- $name = trim( $name );
106
- $content = trim( $content );
107
-
108
- switch ( strtolower( $name ) ) {
109
- // Mainly for legacy -- process a From: header if it's there
110
- case 'from':
111
- if ( false !== strpos( $content, '<' ) ) {
112
- // So... making my life hard again?
113
- $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
114
- $from_name = str_replace( '"', '', $from_name );
115
- $from_name = trim( $from_name );
116
-
117
- $from_email = substr( $content, strpos( $content, '<' ) + 1 );
118
- $from_email = str_replace( '>', '', $from_email );
119
- $from_email = trim( $from_email );
120
- } else {
121
- $from_email = trim( $content );
122
  }
123
- break;
124
- case 'content-type':
125
- if ( false !== strpos( $content, ';' ) ) {
126
- list( $type, $charset ) = explode( ';', $content );
127
- $content_type = trim( $type );
128
- if ( false !== stripos( $charset, 'charset=' ) ) {
129
- $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
130
- } elseif ( false !== stripos( $charset, 'boundary=' ) ) {
131
- $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
132
- $charset = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
- } else {
135
- $content_type = trim( $content );
136
- }
137
- break;
138
- case 'cc':
139
- $cc = array_merge( (array) $cc, explode( ',', $content ) );
140
- foreach ( $cc as $key => $recipient ) {
141
- $cc[ $key ] = trim( $recipient );
142
- }
143
- break;
144
- case 'bcc':
145
- $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
146
- foreach ( $bcc as $key => $recipient ) {
147
- $bcc[ $key ] = trim( $recipient );
148
- }
149
- break;
150
- case 'reply-to':
151
- $replyto = $content;
152
- break;
153
- case 'unique-args':
154
- if ( false !== strpos( $content, ';' ) ) {
155
- $unique_args = explode( ';', $content );
156
- }
157
- else {
158
- $unique_args = (array) trim( $content );
159
- }
160
- foreach ( $unique_args as $unique_arg ) {
161
- if ( false !== strpos( $content, '=' ) ) {
162
- list( $key, $val ) = explode( '=', $unique_arg );
163
- $mail->addUniqueArg( trim( $key ), trim( $val ) );
164
- }
165
- }
166
- break;
167
- case 'template':
168
- $template_ok = Sendgrid_Tools::check_template( trim( $content ) );
169
- if ( $template_ok ) {
170
- $mail->setTemplateId( trim( $content ) );
171
- } elseif ( Sendgrid_Tools::get_template() ) {
172
- $mail->setTemplateId( Sendgrid_Tools::get_template() );
173
- }
174
- break;
175
- case 'categories':
176
- $categories = explode( ',', trim( $content ) );
177
- foreach ( $categories as $category ) {
178
- $mail->addCategory( $category );
179
- }
180
- break;
181
- case 'x-smtpapi-to':
182
- $xsmtpapi_tos = explode( ',', trim( $content ) );
183
- foreach ( $xsmtpapi_tos as $xsmtpapi_to ) {
184
- $mail->addSmtpapiTo( $xsmtpapi_to );
185
- }
186
- break;
187
- case 'substitutions':
188
- if ( false !== strpos( $content, ';' ) ) {
189
- $substitutions = explode( ';', $content );
190
- }
191
- else {
192
- $substitutions = (array) trim( $content );
193
- }
194
- foreach ( $substitutions as $substitution ) {
195
- if ( false !== strpos( $content, '=' ) ) {
196
- list( $key, $val ) = explode( '=', $substitution );
197
- $mail->addSubstitution( '%' . trim( $key ) . '%', explode( ',', trim( $val ) ) );
198
- }
199
- }
200
- break;
201
- default:
202
- // Add it to our grand headers array
203
- $headers[trim( $name )] = trim( $content );
204
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  }
206
  }
207
  }
@@ -209,7 +241,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
209
 
210
  // From email and name
211
  // If we don't have a name from the input headers
212
- if ( !isset( $from_name ) )
213
  $from_name = stripslashes( Sendgrid_Tools::get_from_name() );
214
 
215
  /* If we don't have an email from the input headers default to wordpress@$sitename
@@ -219,9 +251,9 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
219
  * http://trac.wordpress.org/ticket/5007.
220
  */
221
 
222
- if ( !isset( $from_email ) ) {
223
  $from_email = trim( Sendgrid_Tools::get_from_email() );
224
- if (!$from_email) {
225
  // Get the site domain and get rid of www.
226
  $sitename = strtolower( $_SERVER['SERVER_NAME'] );
227
  if ( 'www.' == substr( $sitename, 0, 4 ) ) {
@@ -265,6 +297,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
265
 
266
  $toname = array();
267
  foreach ( (array) $to as $key => $recipient ) {
 
268
  // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
269
  if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
270
  if ( 3 == count( $matches ) ) {
38
  */
39
  function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() )
40
  {
41
+ $header_is_object = false;
42
+
43
+ if ( $headers instanceof SendGrid\Email ) {
44
+ $header_is_object = true;
45
 
46
+ $mail = $headers;
47
 
48
+ // Compact the input, apply the filters, and extract them back out - empty header
49
+ extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', '', 'attachments' ) ) );
50
+
51
+ } else {
52
+ $mail = new SendGrid\Email();
53
+
54
+ // Compact the input, apply the filters, and extract them back out
55
+ extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
56
+ }
57
+
58
+ $method = Sendgrid_Tools::get_send_method();
59
 
60
  // prepare attachments
61
  $attached_files = array();
87
  $cc = array();
88
  $bcc = array();
89
  $unique_args = array();
90
+ $from_name = $mail->getFromName();
91
+ $from_email = $mail->getFrom();
92
+ $replyto = $mail->getReplyTo();
93
+
94
+ if ( false === $header_is_object ) {
95
+ if ( empty( $headers ) ) {
96
+ $headers = array();
97
  } else {
98
+ if ( ! is_array( $headers ) ) {
99
+ // Explode the headers out, so this function can take both
100
+ // string headers and an array of headers.
101
+ $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
102
+ } else {
103
+ $tempheaders = $headers;
104
+ }
105
+ $headers = array();
106
+
107
+ // If it's actually got contents
108
+ if ( ! empty( $tempheaders ) ) {
109
+ // Iterate through the raw headers
110
+ foreach ( (array) $tempheaders as $header ) {
111
+ if ( false === strpos( $header, ':' ) ) {
112
+ if ( false !== stripos( $header, 'boundary=' ) ) {
113
+ $parts = preg_split( '/boundary=/i', trim( $header ) );
114
+ $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
+ continue;
117
+ }
118
+ // Explode them out
119
+ list( $name, $content ) = explode( ':', trim( $header ), 2 );
120
+
121
+ // Cleanup crew
122
+ $name = trim( $name );
123
+ $content = trim( $content );
124
+
125
+ switch ( strtolower( $name ) ) {
126
+ // Mainly for legacy -- process a From: header if it's there
127
+ case 'from':
128
+ if ( false !== strpos( $content, '<' ) ) {
129
+ // So... making my life hard again?
130
+ $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
131
+ $from_name = str_replace( '"', '', $from_name );
132
+ $from_name = trim( $from_name );
133
+
134
+ $from_email = substr( $content, strpos( $content, '<' ) + 1 );
135
+ $from_email = str_replace( '>', '', $from_email );
136
+ $from_email = trim( $from_email );
137
+ } else {
138
+ $from_email = trim( $content );
139
  }
140
+ break;
141
+ case 'content-type':
142
+ if ( false !== strpos( $content, ';' ) ) {
143
+ list( $type, $charset ) = explode( ';', $content );
144
+ $content_type = trim( $type );
145
+ if ( false !== stripos( $charset, 'charset=' ) ) {
146
+ $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
147
+ } elseif ( false !== stripos( $charset, 'boundary=' ) ) {
148
+ $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
149
+ $charset = '';
150
+ }
151
+ } else {
152
+ $content_type = trim( $content );
153
+ }
154
+ break;
155
+ case 'cc':
156
+ $cc = array_merge( (array) $cc, explode( ',', $content ) );
157
+ foreach ( $cc as $key => $recipient ) {
158
+ $cc[ $key ] = trim( $recipient );
159
+ }
160
+ break;
161
+ case 'bcc':
162
+ $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
163
+ foreach ( $bcc as $key => $recipient ) {
164
+ $bcc[ $key ] = trim( $recipient );
165
+ }
166
+ break;
167
+ case 'reply-to':
168
+ $replyto = $content;
169
+ break;
170
+ case 'unique-args':
171
+ if ( false !== strpos( $content, ';' ) ) {
172
+ $unique_args = explode( ';', $content );
173
+ }
174
+ else {
175
+ $unique_args = (array) trim( $content );
176
+ }
177
+ foreach ( $unique_args as $unique_arg ) {
178
+ if ( false !== strpos( $content, '=' ) ) {
179
+ list( $key, $val ) = explode( '=', $unique_arg );
180
+ $mail->addUniqueArg( trim( $key ), trim( $val ) );
181
+ }
182
+ }
183
+ break;
184
+ case 'template':
185
+ $template_ok = Sendgrid_Tools::check_template( trim( $content ) );
186
+ if ( $template_ok ) {
187
+ $mail->setTemplateId( trim( $content ) );
188
+ } elseif ( Sendgrid_Tools::get_template() ) {
189
+ $mail->setTemplateId( Sendgrid_Tools::get_template() );
190
+ }
191
+ break;
192
+ case 'categories':
193
+ $categories = explode( ',', trim( $content ) );
194
+ foreach ( $categories as $category ) {
195
+ $mail->addCategory( $category );
196
+ }
197
+ break;
198
+ case 'x-smtpapi-to':
199
+ $xsmtpapi_tos = explode( ',', trim( $content ) );
200
+ foreach ( $xsmtpapi_tos as $xsmtpapi_to ) {
201
+ $mail->addSmtpapiTo( $xsmtpapi_to );
202
+ }
203
+ break;
204
+ case 'substitutions':
205
+ if ( false !== strpos( $content, ';' ) ) {
206
+ $substitutions = explode( ';', $content );
207
+ }
208
+ else {
209
+ $substitutions = (array) trim( $content );
210
+ }
211
+ foreach ( $substitutions as $substitution ) {
212
+ if ( false !== strpos( $content, '=' ) ) {
213
+ list( $key, $val ) = explode( '=', $substitution );
214
+ $mail->addSubstitution( '%' . trim( $key ) . '%', explode( ',', trim( $val ) ) );
215
+ }
216
+ }
217
+ break;
218
+ case 'sections':
219
+ if ( false !== strpos( $content, ';' ) ) {
220
+ $sections = explode( ';', $content );
221
+ }
222
+ else {
223
+ $sections = (array) trim( $content );
224
+ }
225
+ foreach ( $sections as $section ) {
226
+ if ( false !== strpos( $content, '=' ) ) {
227
+ list( $key, $val ) = explode( '=', $section );
228
+ $mail->addSection( '%' . trim( $key ) . '%', trim( $val ) );
229
+ }
230
+ }
231
+ break;
232
+ default:
233
+ // Add it to our grand headers array
234
+ $headers[trim( $name )] = trim( $content );
235
+ break;
236
+ }
237
  }
238
  }
239
  }
241
 
242
  // From email and name
243
  // If we don't have a name from the input headers
244
+ if ( ! isset( $from_name ) or ! $from_name )
245
  $from_name = stripslashes( Sendgrid_Tools::get_from_name() );
246
 
247
  /* If we don't have an email from the input headers default to wordpress@$sitename
251
  * http://trac.wordpress.org/ticket/5007.
252
  */
253
 
254
+ if ( ! isset( $from_email ) ) {
255
  $from_email = trim( Sendgrid_Tools::get_from_email() );
256
+ if (! $from_email) {
257
  // Get the site domain and get rid of www.
258
  $sitename = strtolower( $_SERVER['SERVER_NAME'] );
259
  if ( 'www.' == substr( $sitename, 0, 4 ) ) {
297
 
298
  $toname = array();
299
  foreach ( (array) $to as $key => $recipient ) {
300
+ $toname[ $key ] = " ";
301
  // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
302
  if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
303
  if ( 3 == count( $matches ) ) {
readme.txt CHANGED
@@ -4,11 +4,11 @@ Donate link: http://sendgrid.com/
4
  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
5
  Requires at least: 3.3
6
  Tested up to: 4.4
7
- Stable tag: 1.7.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Send emails throught Sendgrid from your WordPress installation using SMTP or API integration.
12
 
13
  == Description ==
14
 
@@ -24,7 +24,7 @@ You can also set default values for the "Name", "Sending Address" and the "Reply
24
 
25
  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.
26
 
27
- You can have an individual email sent to each recipient by setting x-smtpapi-to in headers: `'x-smtpapi-to: address1@sendgrid.com,address2@sendgrid.com'`. Note: when using SMTP method you need to have also the `to` address set(this may be dummy data since will be overwritten with the addresses from x-smtpapi-to) in order to be able to send emails.
28
 
29
  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.
30
 
@@ -44,7 +44,7 @@ Where:
44
  * `$to` - Array or comma-separated list of email addresses to send message.
45
  * `$subject` - Email subject
46
  * `$message` - Message contents
47
- * `$headers` - Array or "\n" separated list of additional headers. Optional.
48
  * `$attachments` - Array or "\n"/"," separated list of files to attach. Optional.
49
 
50
  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 `wp_mail()` one.
@@ -53,21 +53,44 @@ After wp_mail function you need to run the `remove_filter('wp_mail_content_type'
53
 
54
  Example about how to send an HTML email using different headers:
55
 
56
- `$subject = 'test plugin';
 
 
57
  $message = 'testing WordPress plugin';
58
- $to = 'address1@sendgrid.com, Address2 <address2@sendgrid.com@>, address3@sendgrid.com';
59
- or
60
  $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
61
 
62
  $headers = array();
63
  $headers[] = 'From: Me Myself <me@example.net>';
64
  $headers[] = 'Cc: address4@sendgrid.com';
65
  $headers[] = 'Bcc: address5@sendgrid.com';
66
- $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
67
- $headers[] = 'categories: category1, category2'
68
- $headers[] = 'template: templateID'
69
- $headers[] = 'substitutions:name=name1,name2;subject=subject1,subject2'
70
- $headers[] = 'x-smtpapi-to: address1@sendgrid.com,address2@sendgrid.com'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
73
 
@@ -76,6 +99,27 @@ $mail = wp_mail($to, $subject, $message, $headers, $attachments);
76
 
77
  remove_filter('wp_mail_content_type', 'set_html_content_type');`
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  == Installation ==
80
 
81
  Requirements:
@@ -120,7 +164,7 @@ SendGrid settings can optionally be defined as global variables (wp-config.php):
120
 
121
  = What credentials do I need to add on settings page =
122
 
123
- Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" target="_blank">http://sendgrid.com/partner/wordpress</a> and use these credentials.
124
 
125
  == Screenshots ==
126
 
@@ -139,6 +183,9 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
139
 
140
  == Changelog ==
141
 
 
 
 
142
  = 1.7.6 =
143
  * Updated validation for email addresses in the headers field of the send test email form
144
  * Add ability to have and individual email sent to each recipient by setting x-smtpapi-to in headers
@@ -236,6 +283,9 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
236
 
237
  == Upgrade notice ==
238
 
 
 
 
239
  = 1.7.6 =
240
  * Updated validation for email addresses in the headers field of the send test email form
241
  * Add ability to have and individual email sent to each recipient by setting x-smtpapi-to in headers
4
  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
5
  Requires at least: 3.3
6
  Tested up to: 4.4
7
+ Stable tag: 1.8.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Send emails throught SendGrid from your WordPress installation using SMTP or API integration.
12
 
13
  == Description ==
14
 
24
 
25
  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.
26
 
27
+ You can have an individual email sent to each recipient by setting x-smtpapi-to in headers: `'x-smtpapi-to: address1@sendgrid.com,address2@sendgrid.com'`. Note: when using SMTP method you need to have also the `to` address set (this may be dummy data since will be overwritten with the addresses from x-smtpapi-to) in order to be able to send emails.
28
 
29
  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.
30
 
44
  * `$to` - Array or comma-separated list of email addresses to send message.
45
  * `$subject` - Email subject
46
  * `$message` - Message contents
47
+ * `$headers` - Array or SendGrid\Email() object. Optional.
48
  * `$attachments` - Array or "\n"/"," separated list of files to attach. Optional.
49
 
50
  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 `wp_mail()` one.
53
 
54
  Example about how to send an HTML email using different headers:
55
 
56
+ Using array for $headers:
57
+
58
+ `$subject = 'Test SendGrid plugin';
59
  $message = 'testing WordPress plugin';
 
 
60
  $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
61
 
62
  $headers = array();
63
  $headers[] = 'From: Me Myself <me@example.net>';
64
  $headers[] = 'Cc: address4@sendgrid.com';
65
  $headers[] = 'Bcc: address5@sendgrid.com';
66
+ $headers[] = 'unique-args:customer=mycustomer;location=mylocation';
67
+ $headers[] = 'categories: category1, category2';
68
+ $headers[] = 'template: templateID';
69
+ $headers[] = 'x-smtpapi-to: address1@sendgrid.com,address2@sendgrid.com';
70
+
71
+ $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
72
+
73
+ add_filter('wp_mail_content_type', 'set_html_content_type');
74
+ $mail = wp_mail($to, $subject, $message, $headers, $attachments);
75
+
76
+ remove_filter('wp_mail_content_type', 'set_html_content_type');`
77
+
78
+
79
+ Using SendGrid\Email() for $headers:
80
+
81
+ `$subject = 'Test SendGrid plugin';
82
+ $message = 'testing WordPress plugin';
83
+ $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
84
+
85
+ $headers = new SendGrid\Email();
86
+ $headers->setFromName("Me Myself")
87
+ ->setFrom("me@example.net")
88
+ ->setCc("address4@sendgrid.com")
89
+ ->setBcc("address5@sendgrid.com")
90
+ ->setUniqueArgs(array('customer' => 'mycustomer', 'location' => 'mylocation'))
91
+ ->addCategory('category1')
92
+ ->addCategory('category2')
93
+ ->setTemplateId('templateID');
94
 
95
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
96
 
99
 
100
  remove_filter('wp_mail_content_type', 'set_html_content_type');`
101
 
102
+ = How to use Substitution and Sections =
103
+
104
+ `$subject = 'Hey %name%, you work at %place%';
105
+ $message = 'testing WordPress plugin';
106
+ $to = array('address1@sendgrid.com');
107
+
108
+ $headers = new SendGrid\Email();
109
+ $headers
110
+ ->addSmtpapiTo("john@somewhere.com")
111
+ ->addSmtpapiTo("harry@somewhere.com")
112
+ ->addSmtpapiTo("Bob@somewhere.com")
113
+ ->addSubstitution("%name%", array("John", "Harry", "Bob"))
114
+ ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
115
+ ->addSection("%office%", "an office")
116
+ ->addSection("%home%", "your house")
117
+ ;
118
+
119
+ $mail = wp_mail($to, $subject, $message, $headers);`
120
+
121
+ More examples for using SendGrid SMTPAPI header: <https://github.com/sendgrid/sendgrid-php#smtpapi>
122
+
123
  == Installation ==
124
 
125
  Requirements:
164
 
165
  = What credentials do I need to add on settings page =
166
 
167
+ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" target="_blank">https://sendgrid.com/partner/wordpress</a> and generate a new API key on <https://app.sendgrid.com/settings/api_keys>.
168
 
169
  == Screenshots ==
170
 
183
 
184
  == Changelog ==
185
 
186
+ = 1.8.0 =
187
+ * Added SendGrid\Email() for $header
188
+ * Fix Send Test form not being displayed issue
189
  = 1.7.6 =
190
  * Updated validation for email addresses in the headers field of the send test email form
191
  * Add ability to have and individual email sent to each recipient by setting x-smtpapi-to in headers
283
 
284
  == Upgrade notice ==
285
 
286
+ = 1.8.0 =
287
+ * Added SendGrid\Email() for $header
288
+ * Fix Send Test form not being displayed issue
289
  = 1.7.6 =
290
  * Updated validation for email addresses in the headers field of the send test email form
291
  * Add ability to have and individual email sent to each recipient by setting x-smtpapi-to in headers
view/sendgrid_contextual_help.php CHANGED
@@ -28,7 +28,34 @@
28
  &lt;?php wp_mail('to@address.com\', 'Email Subject', 'Email Body'); ?&gt;
29
  </div>
30
  <br />
31
- If you want to use additional headers, here you have a more complex example:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <br />
33
  <div class="code">
34
  $subject = 'test plugin'
@@ -46,11 +73,11 @@
46
  <br />
47
  $headers[] = 'Bcc: address5@sendgrid.com';
48
  <br />
49
- $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
50
  <br />
51
- $headers[] = 'categories: category1, category2'
52
  <br />
53
- $headers[] = 'template: templateID'
54
  <br />
55
  <br />
56
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
@@ -62,29 +89,81 @@
62
  <br />
63
  remove_filter('wp_mail_content_type', 'set_html_content_type');
64
  </div>
 
 
65
  <br />
66
- Where:
67
- <br />
68
- <ul>
69
- <li>$to - Array or comma-separated list of email addresses to send message.</li>
70
- <li>$subject - Email subject'); ?></li>
71
- <li>$message - Message contents'); ?></li>
72
- <li>$headers - Array or "\n" separated list of additional headers. Optional.</li>
73
- <li>$attachments - Array or "\n"/"," separated list of files to attach. Optional.</li>
74
- </ul>
75
- The wp_mail function is sending text emails as default. If you want to send an email with HTML content you have
76
- to set the content type to 'text/html' running
77
- <span class="code">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  add_filter('wp_mail_content_type', 'set_html_content_type');
79
- </span>
80
- function before to wp_mail() one.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  <br />
82
  <br />
83
- After wp_mail function you need to run the
84
- <span class="code">
85
- remove_filter('wp_mail_content_type', 'set_html_content_type');
86
- </span>
87
- to remove the 'text/html' filter to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
88
  <p><b>Define SendGrid settings as global variables (wp-config.php):</b></p>
89
  <p>
90
  <ol>
28
  &lt;?php wp_mail('to@address.com\', 'Email Subject', 'Email Body'); ?&gt;
29
  </div>
30
  <br />
31
+ Where:
32
+ <br />
33
+ <ul>
34
+ <li>$to - Array or comma-separated list of email addresses to send message.</li>
35
+ <li>$subject - Email subject</li>
36
+ <li>$message - Message contents></li>
37
+ <li>$headers - Array or SendGrid\Email() object. Optional.</li>
38
+ <li>$attachments - Array or "\n"/"," separated list of files to attach. Optional.</li>
39
+ </ul>
40
+ The wp_mail function is sending text emails as default. If you want to send an email with HTML content you have
41
+ to set the content type to 'text/html' running
42
+ <span class="code">
43
+ add_filter('wp_mail_content_type', 'set_html_content_type');
44
+ </span>
45
+ function before to wp_mail() one.
46
+ <br />
47
+ <br />
48
+ After wp_mail function you need to run the
49
+ <span class="code">
50
+ remove_filter('wp_mail_content_type', 'set_html_content_type');
51
+ </span>
52
+ to remove the 'text/html' filter to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
53
+ <br />
54
+ <br />
55
+ Example about how to send an HTML email using different headers:
56
+ <br />
57
+ <br />
58
+ <b>Using array for $headers:</b>
59
  <br />
60
  <div class="code">
61
  $subject = 'test plugin'
73
  <br />
74
  $headers[] = 'Bcc: address5@sendgrid.com';
75
  <br />
76
+ $headers[] = 'unique-args:customer=mycustomer;location=mylocation';
77
  <br />
78
+ $headers[] = 'categories: category1, category2';
79
  <br />
80
+ $headers[] = 'template: templateID';
81
  <br />
82
  <br />
83
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
89
  <br />
90
  remove_filter('wp_mail_content_type', 'set_html_content_type');
91
  </div>
92
+ <br/>
93
+ <b>Using SendGrid\Email() for $headers:</b>
94
  <br />
95
+ <div class="code">
96
+ $subject = 'Test SendGrid plugin';
97
+ <br />
98
+ $message = 'testing WordPress plugin';
99
+ <br />
100
+ $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
101
+ <br />
102
+ <br />
103
+ $headers = new SendGrid\Email();
104
+ <br />
105
+ $headers<br />
106
+ ->setFromName("Me Myself")
107
+ <br />
108
+ ->setFrom("me@example.net")
109
+ <br />
110
+ ->setCc("address4@sendgrid.com")
111
+ <br />
112
+ ->setBcc("address5@sendgrid.com")
113
+ <br />
114
+ ->setUniqueArgs(array('customer' => 'mycustomer', 'location' => 'mylocation'))
115
+ <br />
116
+ ->addCategory('category1')
117
+ <br />
118
+ ->addCategory('category2')
119
+ <br />
120
+ ->setTemplateId('templateID');
121
+ <br />
122
+ <br />
123
+ $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
124
+ <br />
125
  add_filter('wp_mail_content_type', 'set_html_content_type');
126
+ <br />
127
+ $mail = wp_mail($to, $subject, $message, $headers, $attachments);
128
+ <br />
129
+ remove_filter('wp_mail_content_type', 'set_html_content_type');
130
+ </div>
131
+ <br />
132
+ <b>How to use Substitution and Sections</b>
133
+ <br />
134
+ <div class="code">
135
+ $subject = 'Hey %name%, you work at %place%';
136
+ <br />
137
+ $message = 'testing WordPress plugin';
138
+ <br />
139
+ $to = array('address1@sendgrid.com');
140
+ <br />
141
+ <br />
142
+ $headers = new SendGrid\Email();
143
+ <br />
144
+ $headers
145
+ <br />
146
+ ->addSmtpapiTo("john@somewhere.com")
147
+ <br />
148
+ ->addSmtpapiTo("harry@somewhere.com")
149
+ <br />
150
+ ->addSmtpapiTo("Bob@somewhere.com")
151
+ <br />
152
+ ->addSubstitution("%name%", array("John", "Harry", "Bob"))
153
+ <br />
154
+ ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
155
+ <br />
156
+ ->addSection("%office%", "an office")
157
+ <br />
158
+ ->addSection("%home%", "your house");
159
+ <br />
160
+ <br />
161
+ $mail = wp_mail($to, $subject, $message, $headers);`
162
+ </div>
163
+ <br />
164
+ More examples for using SendGrid SMTPAPI header: <a href="https://github.com/sendgrid/sendgrid-php#smtpapi" target="_blank">https://github.com/sendgrid/sendgrid-php#smtpapi</a>
165
  <br />
166
  <br />
 
 
 
 
 
167
  <p><b>Define SendGrid settings as global variables (wp-config.php):</b></p>
168
  <p>
169
  <ol>
view/sendgrid_settings.php CHANGED
@@ -162,7 +162,7 @@
162
  </p>
163
  </form>
164
  <br />
165
- <?php if ( ! isset($status) or ( 'updated' == $status ) or ( 'error' == $status and isset( $error_type ) and 'sending' == $error_type ) ): ?>
166
  <h2><?php _e('SendGrid Test') ?></h2>
167
  <h3><?php _e('Send a test email with these settings') ?></h3>
168
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
162
  </p>
163
  </form>
164
  <br />
165
+ <?php if ( ! isset($status) or ( 'updated' == $status ) or ( 'valid_auth' == $status) or ( 'error' == $status and isset( $error_type ) and 'sending' == $error_type ) ): ?>
166
  <h2><?php _e('SendGrid Test') ?></h2>
167
  <h3><?php _e('Send a test email with these settings') ?></h3>
168
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
wpsendgrid.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: SendGrid
4
  Plugin URI: http://wordpress.org/plugins/sendgrid-email-delivery-simplified/
5
  Description: Email Delivery. Simplified. 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.
6
- Version: 1.7.6
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified
3
  Plugin Name: SendGrid
4
  Plugin URI: http://wordpress.org/plugins/sendgrid-email-delivery-simplified/
5
  Description: Email Delivery. Simplified. 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.
6
+ Version: 1.8.0
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified