SendGrid - Version 1.7.6

Version Description

  • Updated validation for email addresses in the headers field of the send test email form
  • Add ability to have and individual email sent to each recipient by setting x-smtpapi-to in headers
Download this release

Release Info

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

Code changes from version 1.7.5 to 1.7.6

lib/class-sendgrid-settings.php CHANGED
@@ -347,6 +347,13 @@ class Sendgrid_Settings {
347
  $subject = stripslashes( $params['sendgrid_subj'] );
348
  $body = stripslashes( $params['sendgrid_body'] );
349
  $headers = $params['sendgrid_headers'];
 
 
 
 
 
 
 
350
 
351
  if ( preg_match( '/content-type:\s*text\/html/i', $headers ) ) {
352
  $body_br = nl2br( $body );
347
  $subject = stripslashes( $params['sendgrid_subj'] );
348
  $body = stripslashes( $params['sendgrid_body'] );
349
  $headers = $params['sendgrid_headers'];
350
+ if ( ! Sendgrid_Tools::valid_emails_in_headers( $headers ) ) {
351
+ return array(
352
+ 'message' => 'One or more email addresses in field "headers" are not valid.',
353
+ 'status' => 'error',
354
+ 'error_type' => 'sending'
355
+ );
356
+ }
357
 
358
  if ( preg_match( '/content-type:\s*text\/html/i', $headers ) ) {
359
  $body_br = nl2br( $body );
lib/class-sendgrid-tools.php CHANGED
@@ -543,6 +543,94 @@ class Sendgrid_Tools
543
  return filter_var( $email, FILTER_VALIDATE_EMAIL );
544
  }
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  /**
547
  * Returns the string content of the input with "<url>" replaced by "url"
548
  *
543
  return filter_var( $email, FILTER_VALIDATE_EMAIL );
544
  }
545
 
546
+ /**
547
+ * Returns true if all the emails in the headers are valid, false otherwise
548
+ *
549
+ * @param mixed $headers string or array of headers
550
+ * @return bool
551
+ */
552
+ public static function valid_emails_in_headers( $headers )
553
+ {
554
+ if ( ! is_array( $headers ) ) {
555
+ // Explode the headers out, so this function can take both
556
+ // string headers and an array of headers.
557
+ $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
558
+ } else {
559
+ $tempheaders = $headers;
560
+ }
561
+
562
+ // If it's actually got contents
563
+ if ( ! empty( $tempheaders ) ) {
564
+ // Iterate through the raw headers
565
+ foreach ( (array) $tempheaders as $header ) {
566
+ if ( false === strpos( $header, ':' ) ) {
567
+ continue;
568
+ }
569
+ // Explode them out
570
+ list( $name, $content ) = explode( ':', trim( $header ), 2 );
571
+
572
+ // Cleanup crew
573
+ $name = trim( $name );
574
+ $content = trim( $content );
575
+
576
+ switch ( strtolower( $name ) ) {
577
+ // Mainly for legacy -- process a From: header if it's there
578
+ case 'from':
579
+ if ( false !== strpos( $content, '<' ) ) {
580
+ $from_email = substr( $content, strpos( $content, '<' ) + 1 );
581
+ $from_email = str_replace( '>', '', $from_email );
582
+ $from_email = trim( $from_email );
583
+ } else {
584
+ $from_email = trim( $content );
585
+ }
586
+
587
+ if( ! Sendgrid_Tools::is_valid_email( $from_email ) ) {
588
+ return false;
589
+ }
590
+
591
+ break;
592
+ case 'cc':
593
+ $cc = explode( ',', $content );
594
+ foreach ( $cc as $key => $recipient ) {
595
+ if( ! Sendgrid_Tools::is_valid_email( trim( $recipient ) ) ) {
596
+ return false;
597
+ }
598
+ }
599
+
600
+ break;
601
+ case 'bcc':
602
+ $bcc = explode( ',', $content );
603
+ foreach ( $bcc as $key => $recipient ) {
604
+ if( ! Sendgrid_Tools::is_valid_email( trim( $recipient ) ) ) {
605
+ return false;
606
+ }
607
+ }
608
+
609
+ break;
610
+ case 'reply-to':
611
+ if( ! Sendgrid_Tools::is_valid_email( $content ) ) {
612
+ return false;
613
+ }
614
+
615
+ break;
616
+ case 'x-smtpapi-to':
617
+ $xsmtpapi_tos = explode( ',', trim( $content ) );
618
+ foreach ( $xsmtpapi_tos as $xsmtpapi_to ) {
619
+ if( ! Sendgrid_Tools::is_valid_email( $xsmtpapi_to ) ) {
620
+ return false;
621
+ }
622
+ }
623
+
624
+ break;
625
+ default:
626
+ break;
627
+ }
628
+ }
629
+ }
630
+
631
+ return true;
632
+ }
633
+
634
  /**
635
  * Returns the string content of the input with "<url>" replaced by "url"
636
  *
lib/sendgrid/sendgrid-wp-mail.php CHANGED
@@ -91,7 +91,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
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] ) );
@@ -178,6 +178,12 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
178
  $mail->addCategory( $category );
179
  }
180
  break;
 
 
 
 
 
 
181
  case 'substitutions':
182
  if ( false !== strpos( $content, ';' ) ) {
183
  $substitutions = explode( ';', $content );
@@ -204,7 +210,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
204
  // From email and name
205
  // If we don't have a name from the input headers
206
  if ( !isset( $from_name ) )
207
- $from_name = Sendgrid_Tools::get_from_name();
208
 
209
  /* If we don't have an email from the input headers default to wordpress@$sitename
210
  * Some hosts will block outgoing mail from this address if it doesn't exist but
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] ) );
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 );
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
216
  * Some hosts will block outgoing mail from this address if it doesn't exist but
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -22,7 +22,9 @@ To have the SendGrid plugin running after you have activated it, go to the plugi
22
 
23
  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.
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
  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.
28
 
@@ -65,6 +67,7 @@ $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
65
  $headers[] = 'categories: category1, category2'
66
  $headers[] = 'template: templateID'
67
  $headers[] = 'substitutions:name=name1,name2;subject=subject1,subject2'
 
68
 
69
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
70
 
@@ -131,11 +134,14 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
131
  8. Select the time interval for which you want to see SendGrid statistics and charts.
132
  9. Now you are able to configure port number when using SMTP method.
133
  10. You are able to configure what template to use for sending emails.
134
- 11. You are able to configure categories for which you would like to see your stats.
135
  12. You can use substitutions for emails.
136
 
137
  == Changelog ==
138
 
 
 
 
139
  = 1.7.5 =
140
  * Fixed an issue with the reset password email from Wordpress
141
  * Updated validation for email addresses
@@ -230,6 +236,9 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
230
 
231
  == Upgrade notice ==
232
 
 
 
 
233
  = 1.7.5 =
234
  * Fixed an issue with the reset password email from Wordpress
235
  * Updated validation for email addresses
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
 
22
 
23
  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.
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
 
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
 
134
  8. Select the time interval for which you want to see SendGrid statistics and charts.
135
  9. Now you are able to configure port number when using SMTP method.
136
  10. You are able to configure what template to use for sending emails.
137
+ 11. You are able to configure categories for which you would like to see your stats.
138
  12. You can use substitutions for emails.
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
145
  = 1.7.5 =
146
  * Fixed an issue with the reset password email from Wordpress
147
  * Updated validation for email addresses
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
242
  = 1.7.5 =
243
  * Fixed an issue with the reset password email from Wordpress
244
  * Updated validation for email addresses
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.5
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.7.6
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified