SendGrid - Version 1.5

Version Description

Download this release

Release Info

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

Code changes from version 1.4.1 to 1.5

Files changed (58) hide show
  1. assets/banner-772x250.jpg +0 -0
  2. assets/icon-128x128.png +0 -0
  3. assets/icon-256x256.png +0 -0
  4. assets/screenshot-1.png +0 -0
  5. assets/screenshot-2.png +0 -0
  6. assets/screenshot-3.png +0 -0
  7. assets/screenshot-4.png +0 -0
  8. assets/screenshot-5.png +0 -0
  9. assets/screenshot-6.png +0 -0
  10. assets/screenshot-7.png +0 -0
  11. lib/class-sendgrid-settings.php +62 -43
  12. vendor/sendgrid-php/SendGrid/Smtp.php → lib/class-sendgrid-smtp.php +11 -40
  13. lib/class-sendgrid-statistics.php +10 -6
  14. lib/class-sendgrid-tools.php +122 -12
  15. lib/overwrite-sendgrid-methods.php +38 -13
  16. readme.txt +73 -34
  17. vendor/sendgrid-php/.gitignore +0 -4
  18. vendor/sendgrid-php/.travis.yml +0 -6
  19. vendor/sendgrid-php/CHANGELOG.md +7 -0
  20. vendor/sendgrid-php/MIT.LICENSE +1 -1
  21. vendor/sendgrid-php/Makefile +0 -37
  22. vendor/sendgrid-php/README.md +499 -105
  23. vendor/sendgrid-php/SendGrid.php +0 -44
  24. vendor/sendgrid-php/SendGrid/Api.php +0 -17
  25. vendor/sendgrid-php/SendGrid/Mail.php +0 -721
  26. vendor/sendgrid-php/SendGrid/MailInterface.php +0 -10
  27. vendor/sendgrid-php/SendGrid/Web.php +0 -147
  28. vendor/sendgrid-php/SendGrid_loader.php +0 -14
  29. vendor/sendgrid-php/Test/Mock/Mock_loader.php +0 -14
  30. vendor/sendgrid-php/Test/Mock/SmtpMock.php +0 -14
  31. vendor/sendgrid-php/Test/Mock/WebMock.php +0 -19
  32. vendor/sendgrid-php/Test/SendGrid/ApiTest.php +0 -0
  33. vendor/sendgrid-php/Test/SendGrid/MailTest.php +0 -549
  34. vendor/sendgrid-php/Test/SendGrid/SmtpTest.php +0 -91
  35. vendor/sendgrid-php/Test/SendGrid/WebTest.php +0 -101
  36. vendor/sendgrid-php/Test/SendGridTest.php +0 -36
  37. vendor/sendgrid-php/Test/a_loaderTest.php +0 -7
  38. vendor/sendgrid-php/Test/phpunit.xml +0 -7
  39. vendor/sendgrid-php/composer.json +0 -16
  40. vendor/sendgrid-php/composer.lock +43 -46
  41. vendor/sendgrid-php/lib/SendGrid.php +82 -0
  42. vendor/sendgrid-php/lib/SendGrid/Email.php +411 -0
  43. vendor/sendgrid-php/sendgrid-php.php +4 -0
  44. vendor/sendgrid-php/vendor/autoload.php +7 -0
  45. vendor/sendgrid-php/vendor/composer/ClassLoader.php +386 -0
  46. vendor/sendgrid-php/vendor/composer/autoload_classmap.php +9 -0
  47. vendor/sendgrid-php/vendor/composer/autoload_namespaces.php +11 -0
  48. vendor/sendgrid-php/vendor/composer/autoload_psr4.php +9 -0
  49. vendor/sendgrid-php/vendor/composer/autoload_real.php +50 -0
  50. vendor/sendgrid-php/vendor/composer/installed.json +52 -0
  51. vendor/sendgrid-php/vendor/sendgrid/smtpapi/README.md +251 -0
  52. vendor/sendgrid-php/vendor/sendgrid/smtpapi/lib/Smtpapi.php +20 -0
  53. vendor/sendgrid-php/vendor/sendgrid/smtpapi/lib/Smtpapi/Header.php +139 -0
  54. view/js/sendgrid.stats.js +3 -0
  55. view/sendgrid_contextual_help.php +20 -0
  56. view/sendgrid_settings.php +24 -8
  57. view/sendgrid_stats.php +9 -1
  58. wpsendgrid.php +2 -1
assets/banner-772x250.jpg ADDED
Binary file
assets/icon-128x128.png ADDED
Binary file
assets/icon-256x256.png ADDED
Binary file
assets/screenshot-1.png CHANGED
Binary file
assets/screenshot-2.png CHANGED
Binary file
assets/screenshot-3.png CHANGED
Binary file
assets/screenshot-4.png CHANGED
Binary file
assets/screenshot-5.png CHANGED
Binary file
assets/screenshot-6.png CHANGED
Binary file
assets/screenshot-7.png CHANGED
Binary file
lib/class-sendgrid-settings.php CHANGED
@@ -40,9 +40,9 @@ class Sendgrid_Settings
40
  $body = $_POST['sendgrid_body'];
41
  $headers = $_POST['sendgrid_headers'];
42
  $sent = wp_mail($to, $subject, $body, $headers);
43
- if ( 'api' == get_option('sendgrid_api') )
44
  {
45
- $sent = json_decode( $sent );
46
  if ( "success" == $sent->message )
47
  {
48
  $message = 'Email sent.';
@@ -54,7 +54,7 @@ class Sendgrid_Settings
54
  }
55
 
56
  }
57
- elseif ( 'smtp' == get_option('sendgrid_api') )
58
  {
59
  if ( true === $sent )
60
  {
@@ -68,64 +68,83 @@ class Sendgrid_Settings
68
  } else {
69
  $message = 'Options saved.';
70
  $status = 'updated';
71
-
72
- $user = $_POST['sendgrid_user'];
73
- update_option( 'sendgrid_user', $user );
74
 
75
- $password = $_POST['sendgrid_pwd'];
76
- update_option( 'sendgrid_pwd', $password );
 
 
 
77
 
78
- $method = $_POST['sendgrid_api'];
79
- if ( 'smtp' == $method and ! class_exists('Swift') )
80
  {
81
- $message = 'You must have <a href="http://wordpress.org/plugins/swift-mailer/" target="_blank">' .
82
- 'Swift-mailer plugin</a> installed and activated';
83
- $status = 'error';
84
 
85
- update_option( 'sendgrid_api', 'api' );
86
- } else {
87
- update_option( 'sendgrid_api', $method );
 
88
  }
89
 
90
- $name = $_POST['sendgrid_name'];
91
- update_option( 'sendgrid_from_name', $name );
 
 
 
92
 
93
- $email = $_POST['sendgrid_email'];
94
- update_option( 'sendgrid_from_email', $email );
 
 
 
95
 
96
- $reply_to = $_POST['sendgrid_reply_to'];
97
- update_option( 'sendgrid_reply_to', $reply_to );
 
 
 
98
 
99
- $categories = $_POST['sendgrid_categories'];
100
- update_option( 'sendgrid_categories', $categories );
 
 
 
101
  }
102
  }
103
 
104
- $user = get_option('sendgrid_user');
105
- $password = get_option('sendgrid_pwd');
106
- $method = get_option('sendgrid_api');
107
- $name = get_option('sendgrid_from_name');
108
- $email = get_option('sendgrid_from_email');
109
- $reply_to = get_option('sendgrid_reply_to');
110
- $categories = get_option('sendgrid_categories');
111
-
112
- $valid_credentials = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  if ( $user and $password )
114
  {
115
- if ( in_array( 'curl', get_loaded_extensions() ) )
116
  {
117
- $valid_credentials = Sendgrid_Tools::check_username_password( $user, $password );
118
-
119
- if ( ! $valid_credentials )
120
- {
121
- $message = 'Invalid username/password';
122
- $status = 'error';
123
- }
124
- } else {
125
- $message = 'You must have PHP-curl extension enabled';
126
  $status = 'error';
127
  }
128
  }
 
 
129
 
130
  require_once dirname( __FILE__ ) . '/../view/sendgrid_settings.php';
131
  }
40
  $body = $_POST['sendgrid_body'];
41
  $headers = $_POST['sendgrid_headers'];
42
  $sent = wp_mail($to, $subject, $body, $headers);
43
+ if ( 'api' == Sendgrid_Tools::get_send_method() )
44
  {
45
+ $sent = json_decode( $sent['body'] );
46
  if ( "success" == $sent->message )
47
  {
48
  $message = 'Email sent.';
54
  }
55
 
56
  }
57
+ elseif ( 'smtp' == Sendgrid_Tools::get_send_method() )
58
  {
59
  if ( true === $sent )
60
  {
68
  } else {
69
  $message = 'Options saved.';
70
  $status = 'updated';
 
 
 
71
 
72
+ if (isset($_POST['sendgrid_user']))
73
+ {
74
+ $user = $_POST['sendgrid_user'];
75
+ update_option('sendgrid_user', $user);
76
+ }
77
 
78
+ if (isset($_POST['sendgrid_pwd']))
 
79
  {
80
+ $password = $_POST['sendgrid_pwd'];
81
+ update_option('sendgrid_pwd', $password);
82
+ }
83
 
84
+ if (isset($_POST['sendgrid_api']))
85
+ {
86
+ $method = $_POST['sendgrid_api'];
87
+ update_option('sendgrid_api', $method);
88
  }
89
 
90
+ if (isset($_POST['sendgrid_name']))
91
+ {
92
+ $name = $_POST['sendgrid_name'];
93
+ update_option('sendgrid_from_name', $name);
94
+ }
95
 
96
+ if (isset($_POST['sendgrid_email']))
97
+ {
98
+ $email = $_POST['sendgrid_email'];
99
+ update_option('sendgrid_from_email', $email);
100
+ }
101
 
102
+ if (isset($_POST['sendgrid_reply_to']))
103
+ {
104
+ $reply_to = $_POST['sendgrid_reply_to'];
105
+ update_option('sendgrid_reply_to', $reply_to);
106
+ }
107
 
108
+ if (isset($_POST['sendgrid_categories']))
109
+ {
110
+ $categories = $_POST['sendgrid_categories'];
111
+ update_option('sendgrid_categories', $categories);
112
+ }
113
  }
114
  }
115
 
116
+ $user = Sendgrid_Tools::get_username();
117
+ $password = Sendgrid_Tools::get_password();
118
+ $method = Sendgrid_Tools::get_send_method();
119
+ $name = Sendgrid_Tools::get_from_name();
120
+ $email = Sendgrid_Tools::get_from_email();
121
+ $reply_to = Sendgrid_Tools::get_reply_to();
122
+ $categories = Sendgrid_Tools::get_categories();
123
+
124
+ $allowed_methods = array('smtp', 'api');
125
+ if (!in_array($method, $allowed_methods))
126
+ {
127
+ $message = 'Invalid send method, available methods are: "api" or "smtp".';
128
+ $status = 'error';
129
+ }
130
+
131
+ if ('smtp' == $method and !class_exists('Swift'))
132
+ {
133
+ $message = 'You must have <a href="http://wordpress.org/plugins/swift-mailer/" target="_blank">' .
134
+ 'Swift-mailer plugin</a> installed and activated';
135
+ $status = 'error';
136
+ }
137
+
138
  if ( $user and $password )
139
  {
140
+ if ( ! Sendgrid_Tools::check_username_password( $user, $password ) )
141
  {
142
+ $message = 'Invalid username/password';
 
 
 
 
 
 
 
 
143
  $status = 'error';
144
  }
145
  }
146
+
147
+ $are_global_credentials = ( defined('SENDGRID_USERNAME') and defined('SENDGRID_PASSWORD') );
148
 
149
  require_once dirname( __FILE__ ) . '/../view/sendgrid_settings.php';
150
  }
vendor/sendgrid-php/SendGrid/Smtp.php → lib/class-sendgrid-smtp.php RENAMED
@@ -1,8 +1,6 @@
1
  <?php
2
 
3
- namespace SendGrid;
4
-
5
- class Smtp extends Api implements MailInterface
6
  {
7
  //the available ports
8
  const TLS = 587;
@@ -12,6 +10,8 @@ class Smtp extends Api implements MailInterface
12
  //the list of port instances, to be recycled
13
  private $swift_instances = array();
14
  protected $port;
 
 
15
 
16
  public function __construct($username, $password)
17
  {
@@ -22,7 +22,8 @@ class Smtp extends Api implements MailInterface
22
  if (!class_exists('Swift')) {
23
  require_once 'swift_required.php';
24
  }
25
- call_user_func_array("parent::__construct", func_get_args());
 
26
 
27
  //set the default port
28
  $this->port = Smtp::TLS;
@@ -65,7 +66,7 @@ class Smtp extends Api implements MailInterface
65
  * @param Mail $mail - the SendGridMail object
66
  * @return the SwiftMessage object
67
  */
68
- protected function _mapToSwift(Mail $mail)
69
  {
70
  $message = new \Swift_Message($mail->getSubject());
71
 
@@ -93,36 +94,7 @@ class Smtp extends Api implements MailInterface
93
  if(($replyto = $mail->getReplyTo())) {
94
  $message->setReplyTo($replyto);
95
  }
96
-
97
- // determine whether or not we can use SMTP recipients (non header based)
98
- if($mail->useHeaders())
99
- {
100
- //send header based email
101
- $message->setTo($mail->getFrom());
102
-
103
- //here we'll add the recipients list to the headers
104
- $headers = $mail->getHeaders();
105
- $headers['to'] = $mail->getTos();
106
- $mail->setHeaders($headers);
107
- }
108
- else
109
- {
110
- $recipients = array();
111
- foreach ($mail->getTos() as $recipient)
112
- {
113
- if(preg_match("/(.*)<(.*)>/", $recipient, $results))
114
- {
115
- $recipients[trim($results[2])] = trim($results[1]);
116
- }
117
- else
118
- {
119
- $recipients[] = $recipient;
120
- }
121
- }
122
-
123
- $message->setTo($recipients);
124
- }
125
-
126
  $attachments = $mail->getAttachments();
127
 
128
  //add any attachments that were added
@@ -134,10 +106,9 @@ class Smtp extends Api implements MailInterface
134
  }
135
  }
136
 
137
- //add all the headers
138
- $headers = $message->getHeaders();
139
- $headers->addTextHeader('X-SMTPAPI', $mail->getHeadersJson());
140
-
141
  return $message;
142
  }
143
 
@@ -146,7 +117,7 @@ class Smtp extends Api implements MailInterface
146
  * @param Mail $mail - the SendGridMailMessage to be sent
147
  * @return true if mail was sendable (not necessarily sent)
148
  */
149
- public function send(Mail $mail)
150
  {
151
  $swift = $this->_getSwiftInstance($this->port);
152
 
1
  <?php
2
 
3
+ class Smtp
 
 
4
  {
5
  //the available ports
6
  const TLS = 587;
10
  //the list of port instances, to be recycled
11
  private $swift_instances = array();
12
  protected $port;
13
+ protected $username,
14
+ $password;
15
 
16
  public function __construct($username, $password)
17
  {
22
  if (!class_exists('Swift')) {
23
  require_once 'swift_required.php';
24
  }
25
+ $this->username = $username;
26
+ $this->password = $password;
27
 
28
  //set the default port
29
  $this->port = Smtp::TLS;
66
  * @param Mail $mail - the SendGridMail object
67
  * @return the SwiftMessage object
68
  */
69
+ protected function _mapToSwift(SendGrid\Email $mail)
70
  {
71
  $message = new \Swift_Message($mail->getSubject());
72
 
94
  if(($replyto = $mail->getReplyTo())) {
95
  $message->setReplyTo($replyto);
96
  }
97
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  $attachments = $mail->getAttachments();
99
 
100
  //add any attachments that were added
106
  }
107
  }
108
 
109
+ $message_headers = $message->getHeaders();
110
+ $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString());
111
+
 
112
  return $message;
113
  }
114
 
117
  * @param Mail $mail - the SendGridMailMessage to be sent
118
  * @return true if mail was sendable (not necessarily sent)
119
  */
120
+ public function send(SendGrid\Email $mail)
121
  {
122
  $swift = $this->_getSwiftInstance($this->port);
123
 
lib/class-sendgrid-statistics.php CHANGED
@@ -25,7 +25,7 @@ class Sendgrid_Statistics
25
  */
26
  public static function add_dashboard_widget()
27
  {
28
- if ( ! Sendgrid_Tools::check_username_password( get_option('sendgrid_user'), get_option('sendgrid_pwd') ) ) {
29
  return;
30
  }
31
 
@@ -50,7 +50,7 @@ class Sendgrid_Statistics
50
  */
51
  public static function add_statistics_menu()
52
  {
53
- if ( ! Sendgrid_Tools::check_username_password( get_option('sendgrid_user'), get_option('sendgrid_pwd') ) ) {
54
  return;
55
  }
56
 
@@ -111,8 +111,8 @@ class Sendgrid_Statistics
111
  }
112
 
113
  $parameters = array();
114
- $parameters['api_user'] = get_option('sendgrid_user');
115
- $parameters['api_key'] = get_option('sendgrid_pwd');
116
  $parameters['data_type'] = 'global';
117
  $parameters['metric'] = 'all';
118
 
@@ -123,8 +123,12 @@ class Sendgrid_Statistics
123
  $parameters['end_date'] = $_POST['end_date'];
124
  }
125
 
126
- if ( $_POST['type'] and 'wordpress' == $_POST['type'] ) {
127
- $parameters['category'] = 'wp_sendgrid_plugin';
 
 
 
 
128
  }
129
 
130
  echo Sendgrid_Tools::curl_request( 'api/stats.get.json', $parameters );
25
  */
26
  public static function add_dashboard_widget()
27
  {
28
+ if ( ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() ) ) {
29
  return;
30
  }
31
 
50
  */
51
  public static function add_statistics_menu()
52
  {
53
+ if ( ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() ) ) {
54
  return;
55
  }
56
 
111
  }
112
 
113
  $parameters = array();
114
+ $parameters['api_user'] = Sendgrid_Tools::get_username();
115
+ $parameters['api_key'] = Sendgrid_Tools::get_password();
116
  $parameters['data_type'] = 'global';
117
  $parameters['metric'] = 'all';
118
 
123
  $parameters['end_date'] = $_POST['end_date'];
124
  }
125
 
126
+ if ( $_POST['type'] && 'general' != $_POST['type'] ) {
127
+ if( 'wordpress' == $_POST['type'] ) {
128
+ $parameters['category'] = 'wp_sendgrid_plugin';
129
+ } else {
130
+ $parameters['category'] = urlencode( $_POST['type'] );
131
+ }
132
  }
133
 
134
  echo Sendgrid_Tools::curl_request( 'api/stats.get.json', $parameters );
lib/class-sendgrid-tools.php CHANGED
@@ -14,14 +14,8 @@ class Sendgrid_Tools
14
  $url = 'https://sendgrid.com/api/profile.get.json?';
15
  $url .= "api_user=$username&api_key=$password";
16
 
17
- $ch = curl_init();
18
- curl_setopt( $ch, CURLOPT_URL, $url );
19
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
20
-
21
- $data = curl_exec( $ch );
22
- curl_close( $ch );
23
-
24
- $response = json_decode( $data, true );
25
 
26
  if ( isset( $response['error'] ) )
27
  {
@@ -41,10 +35,126 @@ class Sendgrid_Tools
41
  public static function curl_request( $api = 'api/stats.get.json', $parameters = array() )
42
  {
43
  $data = urldecode( http_build_query( $parameters ) );
44
- $process = curl_init();
45
- curl_setopt( $process, CURLOPT_URL, "http://sendgrid.com/$api?$data" );
46
- curl_setopt( $process, CURLOPT_RETURNTRANSFER, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- return curl_exec( $process );
49
  }
50
  }
14
  $url = 'https://sendgrid.com/api/profile.get.json?';
15
  $url .= "api_user=$username&api_key=$password";
16
 
17
+ $response = wp_remote_get( $url );
18
+ $response = json_decode( $response['body'], true );
 
 
 
 
 
 
19
 
20
  if ( isset( $response['error'] ) )
21
  {
35
  public static function curl_request( $api = 'api/stats.get.json', $parameters = array() )
36
  {
37
  $data = urldecode( http_build_query( $parameters ) );
38
+ $url = "https://sendgrid.com/$api?$data";
39
+
40
+ $response = wp_remote_get( $url );
41
+
42
+ return $response['body'];
43
+ }
44
+
45
+ /**
46
+ * Return username from the database or global variable
47
+ *
48
+ * @return string username
49
+ */
50
+ public static function get_username()
51
+ {
52
+ if ( defined('SENDGRID_USERNAME') and defined('SENDGRID_PASSWORD') ) {
53
+ return SENDGRID_USERNAME;
54
+ } else {
55
+ return get_option('sendgrid_user');
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Return password from the database or global variable
61
+ *
62
+ * @return string password
63
+ */
64
+ public static function get_password()
65
+ {
66
+ if ( defined('SENDGRID_USERNAME') and defined('SENDGRID_PASSWORD') ) {
67
+ return SENDGRID_PASSWORD;
68
+ } else {
69
+ return get_option('sendgrid_pwd');
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Return send method from the database or global variable
75
+ *
76
+ * @return string send_method
77
+ */
78
+ public static function get_send_method()
79
+ {
80
+ if ( defined('SENDGRID_SEND_METHOD') ) {
81
+ return SENDGRID_SEND_METHOD;
82
+ } elseif ( get_option('sendgrid_api') ) {
83
+ return get_option('sendgrid_api');
84
+ } else {
85
+ return 'api';
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Return from name from the database or global variable
91
+ *
92
+ * @return string from_name
93
+ */
94
+ public static function get_from_name()
95
+ {
96
+ if ( defined('SENDGRID_FROM_NAME') ) {
97
+ return SENDGRID_FROM_NAME;
98
+ } else {
99
+ return get_option('sendgrid_from_name');
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Return from email address from the database or global variable
105
+ *
106
+ * @return string from_email
107
+ */
108
+ public static function get_from_email()
109
+ {
110
+ if ( defined('SENDGRID_FROM_EMAIL') ) {
111
+ return SENDGRID_FROM_EMAIL;
112
+ } else {
113
+ return get_option('sendgrid_from_email');
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Return reply to email address from the database or global variable
119
+ *
120
+ * @return string reply_to
121
+ */
122
+ public static function get_reply_to()
123
+ {
124
+ if ( defined('SENDGRID_REPLY_TO') ) {
125
+ return SENDGRID_REPLY_TO;
126
+ } else {
127
+ return get_option('sendgrid_reply_to');
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Return categories from the database or global variable
133
+ *
134
+ * @return string categories
135
+ */
136
+ public static function get_categories()
137
+ {
138
+ if ( defined('SENDGRID_CATEGORIES') ) {
139
+ return SENDGRID_CATEGORIES;
140
+ } else {
141
+ return get_option('sendgrid_categories');
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Return categories array
147
+ *
148
+ * @return array categories
149
+ */
150
+ public static function get_categories_array()
151
+ {
152
+ $categories = Sendgrid_Tools::get_categories();
153
+ if ( strlen( trim( $categories ) ) )
154
+ {
155
+ return explode( ',', $categories );
156
+ }
157
 
158
+ return array();
159
  }
160
  }
lib/overwrite-sendgrid-methods.php CHANGED
@@ -2,12 +2,34 @@
2
 
3
  if ( ! function_exists('wp_mail'))
4
  {
5
- require_once plugin_dir_path( __FILE__ ) . '../vendor/sendgrid-php/SendGrid_loader.php';
6
 
7
  define( 'SENDGRID_CATEGORY', 'wp_sendgrid_plugin' );
8
  define( 'SENDGRID_PLUGIN_SETTINGS', 'settings_page_sendgrid-settings' );
9
  define( 'SENDGRID_PLUGIN_STATISTICS', 'dashboard_page_sendgrid-statistics' );
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  /**
12
  * Send mail, similar to PHP's mail
13
  *
@@ -43,9 +65,10 @@ if ( ! function_exists('wp_mail'))
43
  */
44
  function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() )
45
  {
46
- $sendgrid = new SendGrid( get_option('sendgrid_user'), get_option('sendgrid_pwd') );
47
- $mail = new SendGrid\Mail();
48
- $method = get_option( 'sendgrid_api' );
 
49
 
50
  // Compact the input, apply the filters, and extract them back out
51
  extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
@@ -166,7 +189,7 @@ if ( ! function_exists('wp_mail'))
166
  // From email and name
167
  // If we don't have a name from the input headers
168
  if ( !isset( $from_name ) )
169
- $from_name = get_option( 'sendgrid_from_name' );
170
 
171
  /* If we don't have an email from the input headers default to wordpress@$sitename
172
  * Some hosts will block outgoing mail from this address if it doesn't exist but
@@ -176,7 +199,7 @@ if ( ! function_exists('wp_mail'))
176
  */
177
 
178
  if ( !isset( $from_email ) ) {
179
- $from_email = trim( get_option('sendgrid_from_email') );
180
  if (!$from_email)
181
  {
182
  // Get the site domain and get rid of www.
@@ -248,19 +271,19 @@ if ( ! function_exists('wp_mail'))
248
  $mail->setTos( $to )
249
  ->setSubject( $subject )
250
  ->setText( $message )
251
- ->setCategory( SENDGRID_CATEGORY )
252
  ->setFrom( $from_email );
253
 
254
- $categories = explode( ',', get_option('sendgrid_categories') );
255
  foreach ($categories as $category)
256
  {
257
  $mail->addCategory($category);
258
  }
259
 
260
  // send HTML content
261
- if ( 'text/plain' !== $content_type )
262
  {
263
- $mail->setHtml( $message );
264
  }
265
  // set from name
266
  if ( $from_email )
@@ -279,7 +302,7 @@ if ( ! function_exists('wp_mail'))
279
  }
280
  if ( ! isset( $replyto ) )
281
  {
282
- $replyto = trim( get_option('sendgrid_reply_to') );
283
  }
284
  $reply_to_found = preg_match( '/.*<(.*)>.*/i', $replyto, $result );
285
  if ( $reply_to_found )
@@ -299,13 +322,15 @@ if ( ! function_exists('wp_mail'))
299
  {
300
  if ( 'api' == $method )
301
  {
302
- return $sendgrid->web->send( $mail );
303
  }
304
  elseif ( 'smtp' == $method )
305
  {
306
  if ( class_exists('Swift') )
307
  {
308
- return $sendgrid->smtp->send( $mail );
 
 
309
  }
310
  else
311
  {
2
 
3
  if ( ! function_exists('wp_mail'))
4
  {
5
+ require( plugin_dir_path( __FILE__ ) . '../vendor/sendgrid-php/sendgrid-php.php' );
6
 
7
  define( 'SENDGRID_CATEGORY', 'wp_sendgrid_plugin' );
8
  define( 'SENDGRID_PLUGIN_SETTINGS', 'settings_page_sendgrid-settings' );
9
  define( 'SENDGRID_PLUGIN_STATISTICS', 'dashboard_page_sendgrid-statistics' );
10
 
11
+ /**
12
+ * Override Email send
13
+ *
14
+ * @param SendGrid\Email $email Email object with email info
15
+ * @param SendGrid $sendgrid Sendgrid object with credentials info
16
+ * @return array Array of results
17
+ */
18
+ function wp_send( SendGrid\Email $email, $sendgrid )
19
+ {
20
+ $form = $email->toWebFormat();
21
+ $form['api_user'] = Sendgrid_Tools::get_username();
22
+ $form['api_key'] = Sendgrid_Tools::get_password();
23
+
24
+ $form = array(
25
+ 'body' => $form
26
+ );
27
+
28
+ $response = wp_remote_post( $sendgrid->url, $form );
29
+
30
+ return $response;
31
+ }
32
+
33
  /**
34
  * Send mail, similar to PHP's mail
35
  *
65
  */
66
  function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() )
67
  {
68
+ $sendgrid = new SendGrid( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() );
69
+ $mail = new SendGrid\Email();
70
+
71
+ $method = Sendgrid_Tools::get_send_method();
72
 
73
  // Compact the input, apply the filters, and extract them back out
74
  extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
189
  // From email and name
190
  // If we don't have a name from the input headers
191
  if ( !isset( $from_name ) )
192
+ $from_name = Sendgrid_Tools::get_from_name();
193
 
194
  /* If we don't have an email from the input headers default to wordpress@$sitename
195
  * Some hosts will block outgoing mail from this address if it doesn't exist but
199
  */
200
 
201
  if ( !isset( $from_email ) ) {
202
+ $from_email = trim( Sendgrid_Tools::get_from_email() );
203
  if (!$from_email)
204
  {
205
  // Get the site domain and get rid of www.
271
  $mail->setTos( $to )
272
  ->setSubject( $subject )
273
  ->setText( $message )
274
+ ->addCategory( SENDGRID_CATEGORY )
275
  ->setFrom( $from_email );
276
 
277
+ $categories = explode( ',', Sendgrid_Tools::get_categories() );
278
  foreach ($categories as $category)
279
  {
280
  $mail->addCategory($category);
281
  }
282
 
283
  // send HTML content
284
+ if ( 'text/plain' !== $content_type )
285
  {
286
+ $mail->setHtml( $message );
287
  }
288
  // set from name
289
  if ( $from_email )
302
  }
303
  if ( ! isset( $replyto ) )
304
  {
305
+ $replyto = trim( Sendgrid_Tools::get_reply_to() );
306
  }
307
  $reply_to_found = preg_match( '/.*<(.*)>.*/i', $replyto, $result );
308
  if ( $reply_to_found )
322
  {
323
  if ( 'api' == $method )
324
  {
325
+ return wp_send( $mail, $sendgrid );
326
  }
327
  elseif ( 'smtp' == $method )
328
  {
329
  if ( class_exists('Swift') )
330
  {
331
+ $smtp = new Smtp( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() );
332
+
333
+ return $smtp->send( $mail );
334
  }
335
  else
336
  {
readme.txt CHANGED
@@ -3,12 +3,12 @@ Contributors: team-rs
3
  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.0
7
- Stable tag: 1.4.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Email Delivery. Simplified.
12
 
13
  == Description ==
14
 
@@ -27,11 +27,11 @@ Emails are tracked and automatically tagged for statistics within the SendGrid D
27
  There are a couple levels of integration between your WordPress installation and the SendGrid plugin:
28
 
29
  * The simplest option is to Install it, Configure it, and the SendGrid plugin for WordPress will start sending your emails through SendGrid.
30
- * We amended wp_mail() function so all email sends from wordpress should go through SendGrid. The wp_mail function is sending text emails as default, but you have an option of sending an email with HTML content.
31
 
32
  How to use `wp_mail()` function:
33
 
34
- We amended `wp_mail()` function so all email sends from wordpress should go through SendGrid.
35
 
36
  You can send emails using the following function: `wp_mail($to, $subject, $message, $headers = '', $attachments = array())`
37
 
@@ -50,7 +50,7 @@ After wp_mail function you need to run the `remove_filter('wp_mail_content_type'
50
  Example about how to send an HTML email using different headers:
51
 
52
  `$subject = 'test plugin';
53
- $message = 'testing wordpress plugin';
54
  $to = 'address1@sendgrid.com, Address2 <address2@sendgrid.com@>, address3@sendgrid.com';
55
  or
56
  $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
@@ -89,6 +89,19 @@ To auto install the SendGrid Plugin from the WordPress admin:
89
  4. Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" target="_blank">http://sendgrid.com/partner/wordpress</a>
90
  5. Navigate to "Settings" -> "SendGrid Settings" and enter your SendGrid credentials
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  == Frequently asked questions ==
93
 
94
  = What credentials do I need to add on settings page =
@@ -107,38 +120,64 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
107
 
108
  == Changelog ==
109
 
110
- = 1.0 =
111
- * Fixed issue: Add error message when PHP-curl extension is not enabled.
112
- = 1.1 =
113
- * Added SendGrid Statistics
114
- = 1.1.1 =
115
- * Added default category on sending
116
- = 1.1.2 =
117
- * Fix display for october charts
118
- = 1.1.3 =
119
- * Fix missing argument warning message
120
- = 1.2 =
121
- * Added statistics for emails sent through wordpress plugin
122
- = 1.2.1 =
123
- * Fix errors: set_html_content_type error, WP_DEBUG enabled notice, Reply-To header is overwritten by default option
124
- = 1.3 =
125
- * Added support for Wordpress 3.8, fixed visual issues for Wordpress 3.7
126
- = 1.3.1 =
127
- * Fixed reply-to to accept: "name <email@example.com>"
128
- = 1.3.2 =
129
- * Fix URL for loading image
130
  = 1.4 =
131
  * Fix warnings for static method, add notice for php version < 5.3.0, refactor plugin code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  == Upgrade notice ==
134
 
135
- = 1.1 =
136
- * SendGrid Statistics can be used by selecting the time interval for which you want to see your statistics.
137
- = 1.2 =
138
- * Now you can switch between Sendgrid general statistics and Sendgrid wordpress statistics.
139
- = 1.3 =
140
- * Added support for Wordpress 3.8, fixed visual issues for Wordpress 3.7
 
 
 
 
 
 
 
 
141
  = 1.4 =
142
  * Fix warnings for static method, add notice for php version < 5.3.0, refactor plugin code
143
- = 1.4.1 =
144
- * Added support to set additional categories
 
 
 
 
3
  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.0.1
7
+ Stable tag: 1.5.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
 
27
  There are a couple levels of integration between your WordPress installation and the SendGrid plugin:
28
 
29
  * The simplest option is to Install it, Configure it, and the SendGrid plugin for WordPress will start sending your emails through SendGrid.
30
+ * We amended wp_mail() function so all email sends from WordPress should go through SendGrid. The wp_mail function is sending text emails as default, but you have an option of sending an email with HTML content.
31
 
32
  How to use `wp_mail()` function:
33
 
34
+ We amended `wp_mail()` function so all email sends from WordPress should go through SendGrid.
35
 
36
  You can send emails using the following function: `wp_mail($to, $subject, $message, $headers = '', $attachments = array())`
37
 
50
  Example about how to send an HTML email using different headers:
51
 
52
  `$subject = 'test plugin';
53
+ $message = 'testing WordPress plugin';
54
  $to = 'address1@sendgrid.com, Address2 <address2@sendgrid.com@>, address3@sendgrid.com';
55
  or
56
  $to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
89
  4. Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" target="_blank">http://sendgrid.com/partner/wordpress</a>
90
  5. Navigate to "Settings" -> "SendGrid Settings" and enter your SendGrid credentials
91
 
92
+ Define SendGrid settings as global variables (wp-config.php):
93
+
94
+ 1. Set credentials (both need to be set in order to get credentials from variables and not from the database):
95
+ * Username: define('SENDGRID_USERNAME', 'sendgrid_username');
96
+ * Password: define('SENDGRID_PASSWORD', 'sendgrid_password');
97
+
98
+ 2. Set email related settings:
99
+ * Send method ('api' or 'smtp'): define('SENDGRID_SEND_METHOD', 'api');
100
+ * From name: define('SENDGRID_FROM_NAME', 'Example Name');
101
+ * From email: define('SENDGRID_FROM_EMAIL', 'from_email@example.com');
102
+ * Reply to email: define('SENDGRID_REPLY_TO', 'reply_to@example.com');
103
+ * Categories: define('SENDGRID_CATEGORIES', 'category_1,category_2');
104
+
105
  == Frequently asked questions ==
106
 
107
  = What credentials do I need to add on settings page =
120
 
121
  == Changelog ==
122
 
123
+ = 1.5.0 =
124
+ * Updated the plugin to use the last version of Sendgrid library: https://github.com/sendgrid/sendgrid-php/releases/tag/v2.2.0
125
+ = 1.4.6 =
126
+ * Added constants for SendGrid settings
127
+ = 1.4.5 =
128
+ * Fix changelog order in readme file
129
+ = 1.4.4 =
130
+ * Fix unicode filename for icon-128x128.png image
131
+ = 1.4.3 =
132
+ * Update plugin logo, description, screenshots on installation page
133
+ = 1.4.2 =
134
+ * Added SendGrid Statistics for the categories added in the SendGrid Settings Page
135
+ = 1.4.1 =
136
+ * Added support to set additional categories
 
 
 
 
 
 
137
  = 1.4 =
138
  * Fix warnings for static method, add notice for php version < 5.3.0, refactor plugin code
139
+ = 1.3.2 =
140
+ * Fix URL for loading image
141
+ = 1.3.1 =
142
+ * Fixed reply-to to accept: "name <email@example.com>"
143
+ = 1.3 =
144
+ * Added support for WordPress 3.8, fixed visual issues for WordPress 3.7
145
+ = 1.2.1 =
146
+ * Fix errors: set_html_content_type error, WP_DEBUG enabled notice, Reply-To header is overwritten by default option
147
+ = 1.2 =
148
+ * Added statistics for emails sent through WordPress plugin
149
+ = 1.1.3 =
150
+ * Fix missing argument warning message
151
+ = 1.1.2 =
152
+ * Fix display for october charts
153
+ = 1.1.1 =
154
+ * Added default category on sending
155
+ = 1.1 =
156
+ * Added SendGrid Statistics
157
+ = 1.0 =
158
+ * Fixed issue: Add error message when PHP-curl extension is not enabled.
159
 
160
  == Upgrade notice ==
161
 
162
+ = 1.5.0 =
163
+ * Updated the plugin to use the last version of Sendgrid library: https://github.com/sendgrid/sendgrid-php/releases/tag/v2.2.0
164
+ = 1.4.6 =
165
+ * Added constants for SendGrid settings
166
+ = 1.4.5 =
167
+ * Fix changelog order in readme file
168
+ = 1.4.4 =
169
+ * Fix unicode filename for icon-128x128.png image
170
+ = 1.4.3 =
171
+ * Update plugin logo, description, screenshots on installation page
172
+ = 1.4.2 =
173
+ * Added SendGrid Statistics for the categories added in the SendGrid Settings Page
174
+ = 1.4.1 =
175
+ * Added support to set additional categories
176
  = 1.4 =
177
  * Fix warnings for static method, add notice for php version < 5.3.0, refactor plugin code
178
+ = 1.3 =
179
+ * Added support for WordPress 3.8, fixed visual issues for WordPress 3.7
180
+ = 1.2 =
181
+ * Now you can switch between Sendgrid general statistics and Sendgrid WordPress statistics.
182
+ = 1.1 =
183
+ * SendGrid Statistics can be used by selecting the time interval for which you want to see your statistics.
vendor/sendgrid-php/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- Test/coverage/*
2
- examples/*
3
- dist/
4
- vendor/*
 
 
 
 
vendor/sendgrid-php/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: php
2
- php:
3
- - 5.4
4
- - 5.3
5
- before_install: composer install --prefer-source
6
- script: make test
 
 
 
 
 
 
vendor/sendgrid-php/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ v2.2.0 (2014-01-12)
2
+ ===================
3
+
4
+ * Remove [Unirest](https://github.com/Mashape/unirest-php/) and replace with native cURL
5
+ * Add CHANGELOG.md
6
+
7
+ --
vendor/sendgrid-php/MIT.LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 SendGrid
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
  documentation files (the "Software"), to deal in the Software without restriction, including without limitation
1
+ Copyright (c) 2013 SendGrid
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
  documentation files (the "Software"), to deal in the Software without restriction, including without limitation
vendor/sendgrid-php/Makefile DELETED
@@ -1,37 +0,0 @@
1
- # Twilio API helper library.
2
- # See LICENSE file for copyright and license details.
3
-
4
- define LICENSE
5
- <?php
6
-
7
- /**
8
- * SendGrid API helper library.
9
- *
10
- * @category Services
11
- * @package Services_SendGrid
12
- * @license http://creativecommons.org/licenses/MIT/ MIT
13
- * @link https://github.com/sendgrid/sendgrid-php
14
- */
15
- endef
16
- export LICENSE
17
-
18
- all: test
19
-
20
- clean:
21
- @rm -rf dist
22
-
23
- PHP_FILES = `find dist -name \*.php`
24
- dist: clean
25
- @mkdir dist
26
- @git archive master | (cd dist; tar xf -)
27
- @for php in $(PHP_FILES); do\
28
- echo "$$LICENSE" > $$php.new; \
29
- tail -n+2 $$php >> $$php.new; \
30
- mv $$php.new $$php; \
31
- done
32
-
33
- test:
34
- @echo running tests
35
- @phpunit --strict --colors --configuration Test/phpunit.xml
36
-
37
- .PHONY: all clean dist test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/README.md CHANGED
@@ -1,191 +1,422 @@
1
- # sendgrid-php
 
2
  This library allows you to quickly and easily send emails through SendGrid using PHP.
3
 
4
- ## Installation
5
 
6
- There are a number of ways to install the SendGrid PHP helper library. Choose from the options outlined below:
7
 
8
- ### Composer
 
 
 
 
 
 
 
 
 
 
9
 
10
- The easier way to install the SendGrid php library is using [Composer](http://getcomposer.org/). Composer makes it easy
11
- to install the library and all of its dependencies:
12
 
13
- #### 1. Update your composer.json
14
 
15
- If you already have a `composer.json`, just add the following to your require section:
16
 
17
  ```json
18
- {
19
  "require": {
20
- "sendgrid/sendgrid": "~1.0.0"
21
  }
22
  }
23
  ```
24
- *For more info on creating a `composer.json`, check out [this guide](http://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup).*
25
 
26
- #### 2. Install from packagist
27
-
28
- To install the library and it's dependencies, make sure you have [composer installed](http://getcomposer.org/doc/01-basic-usage.md#installation) and type the following:
29
 
30
  ```bash
31
- composer install
32
  ```
33
 
34
- #### 3. Include autoload.php
 
 
35
 
36
- Now that we have everything installed, all we need to do is require it from our php script. Add the following to the top of your php script:
 
 
37
 
38
  ```php
39
- require 'vendor/autoload.php';
40
  ```
41
 
42
- This will include both the SendGrid library, and the SwiftMailer dependency.
43
 
44
- ### Git
45
 
46
- You can also install the package from github, although you will have to manually install the dependencies (see the section on installing dependencies below):
47
 
48
- ```bash
49
- git clone https://github.com/sendgrid/sendgrid-php.git
 
 
 
 
50
  ```
51
 
52
- And the require the autoloader from your php script:
53
 
54
  ```php
55
- require '../path/to/sendgrid-php/SendGrid_loader.php';
 
 
 
 
 
 
56
  ```
57
 
58
- ## Installing Dependenices
59
 
60
- If you installed the library using composer or you're not planning on sending using SMTP, you can skip this section. Otherwise, you will need to install
61
- SwiftMailer (which sendgrid-php depends on). You can install from pear using the following:
 
62
 
63
- ```bash
64
- pear channel-discover pear.swiftmailer.org
65
- pear install swift/swift
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  ```
67
 
 
68
 
69
- ## Testing ##
 
 
 
 
70
 
71
- The existing tests in the `Test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:
72
 
73
- ````
74
- phpunit Test/
 
 
 
 
 
75
  ```
76
 
77
- ## SendGrid APIs ##
78
- SendGrid provides two methods of sending email: the Web API, and SMTP API. SendGrid recommends using the SMTP API for sending emails.
79
- For an explanation of the benefits of each, refer to http://docs.sendgrid.com/documentation/get-started/integrate/examples/smtp-vs-rest/.
80
 
81
- This library implements a common interface to make it very easy to use either API.
 
 
 
 
 
 
82
 
83
- ## Mail Pre-Usage ##
84
 
85
- Before we begin using the library, its important to understand a few things about the library architecture...
86
 
87
- * The SendGrid Mail object is the means of setting mail data. In general, data can be set in three ways for most elements:
88
- 1. set - reset the data, and initialize it to the given element. This will destroy previous data
89
- 2. set (List) - for array based elements, we provide a way of passing the entire array in at once. This will also destroy previous data.
90
- 3. add - append data to the list of elements.
 
91
 
92
- * Sending an email is as simple as :
93
- 1. Creating a SendGrid Instance
94
- 1. Creating a SendGrid Mail object, and setting its data
95
- 1. Sending the mail using either SMTP API or Web API.
96
 
97
- ## Mail Usage ##
 
 
 
 
98
 
99
- To begin using this library, initialize the SendGrid object with your SendGrid credentials
100
 
101
  ```php
102
- $sendgrid = new SendGrid('username', 'password');
 
 
 
103
  ```
104
 
105
- Create a new SendGrid Mail object and add your message details
106
 
107
  ```php
108
- $mail = new SendGrid\Mail();
109
- $mail->addTo('foo@bar.com')->
110
- setFrom('me@bar.com')->
111
- setSubject('Subject goes here')->
112
- setText('Hello World!')->
113
- setHtml('<strong>Hello World!</strong>');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  ```
115
 
116
- Send it using the API of your choice (SMTP or Web)
117
 
118
  ```php
119
- $sendgrid->smtp->send($mail);
 
 
120
  ```
121
- Or
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  ```php
124
- $sendgrid->web->send($mail);
 
 
125
  ```
126
 
127
- ### Using Categories ###
 
 
 
 
 
 
 
 
 
 
128
 
129
  Categories are used to group email statistics provided by SendGrid.
130
 
131
  To use a category, simply set the category name. Note: there is a maximum of 10 categories per email.
132
 
 
 
133
  ```php
134
- $mail = new SendGrid\Mail();
135
- $mail->addTo('foo@bar.com')->
136
  ...
137
  addCategory("Category 1")->
138
  addCategory("Category 2");
139
  ```
140
 
 
141
 
142
- ### Using Attachments ###
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  Attachments are currently file based only, with future plans for an in memory implementation as well.
145
 
146
  File attachments are limited to 7 MB per file.
147
 
 
 
148
  ```php
149
- $mail = new SendGrid\Mail();
150
- $mail->addTo('foo@bar.com')->
151
  ...
152
- addAttachment("../path/to/file.txt");
153
  ```
154
 
155
- ### Using From-Name and Reply-To
156
 
157
- There are two handy helper methods for setting the From-Name and Reply-To for a
158
- message
 
 
 
 
 
 
159
 
160
  ```php
161
- $mail = new SendGrid\Mail();
162
- $mail->addTo('foo@bar.com')->
163
- setReplyTo('someone.else@example.com')->
164
- setFromName('John Doe')->
 
 
 
 
 
 
 
 
165
  ...
 
 
 
 
 
 
 
 
 
 
 
166
  ```
167
 
168
- ### Using Substitutions ###
 
 
 
 
 
 
 
169
 
170
  Substitutions can be used to customize multi-recipient emails, and tailor them for the user
171
 
 
 
172
  ```php
173
- $mail = new SendGrid\Mail();
174
- $mail->addTo('john@somewhere.com')->
175
- addTo("harry@somewhere.com")->
176
- addTo("Bob@somewhere.com")->
177
  ...
178
- setHtml("Hey %name%, we've seen that you've been gone for a while")->
179
- addSubstitution("%name%", array("John", "Harry", "Bob"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  ```
181
 
182
- ### Using Sections ###
183
 
184
- Sections can be used to further customize messages for the end users. A section is only useful in conjunction with a substition value.
 
 
185
 
186
  ```php
187
- $mail = new SendGrid\Mail();
188
- $mail->addTo('john@somewhere.com')->
189
  addTo("harry@somewhere.com")->
190
  addTo("Bob@somewhere.com")->
191
  ...
@@ -196,39 +427,202 @@ $mail->addTo('john@somewhere.com')->
196
  addSection("%home%", "your house");
197
  ```
198
 
199
- ### Using Unique Arguments ###
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
  Unique Arguments are used for tracking purposes
202
 
 
 
203
  ```php
204
- $mail = new SendGrid\Mail();
205
- $mail->addTo('foo@bar.com')->
206
  ...
207
- addUniqueArgument("Customer", "Someone")->
208
- addUniqueArgument("location", "Somewhere");
209
  ```
210
 
211
- ### Using Filter Settings ###
 
 
 
 
 
 
 
 
 
212
 
213
  Filter Settings are used to enable and disable apps, and to pass parameters to those apps.
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  ```php
216
- $mail = new SendGrid\Mail();
217
- $mail->addTo('foo@bar.com')->
218
  ...
219
- addFilterSetting("gravatar", "enable", 1)->
220
- addFilterSetting("footer", "enable", 1)->
221
- addFilterSetting("footer", "text/plain", "Here is a plain text footer")->
222
- addFilterSetting("footer", "text/html", "<p style='color:red;'>Here is an HTML footer</p>");
223
  ```
224
 
225
- ### Using Headers ###
 
 
 
 
 
 
 
226
 
227
- Headers can be used to add existing sendgrid functionality (such as for categories or filters), or custom headers can be added as necessary.
228
 
229
  ```php
230
- $mail = new SendGrid\Mail();
231
- $mail->addTo('foo@bar.com')->
232
  ...
233
- addHeader("category", "My New Category");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  ```
 
 
 
 
 
 
 
 
 
 
1
+ # SendGrid-php
2
+
3
  This library allows you to quickly and easily send emails through SendGrid using PHP.
4
 
5
+ WARNING: This module was recently upgraded from [1.1.7](https://github.com/sendgrid/sendgrid-php/tree/v1.1.7) to 2.X. There were API breaking changes for various method names. See [usage](https://github.com/sendgrid/sendgrid-php#usage) for up to date method names.
6
 
7
+ Important: This library requires PHP 5.3 or higher.
8
 
9
+ [![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-php.png?branch=master)](https://travis-ci.org/sendgrid/sendgrid-php)
10
+ [![Latest Stable Version](https://poser.pugx.org/sendgrid/sendgrid/version.png)](https://packagist.org/packages/sendgrid/sendgrid)
11
+
12
+ ```php
13
+ $sendgrid = new SendGrid('username', 'password');
14
+ $email = new SendGrid\Email();
15
+ $email->addTo('foo@bar.com')->
16
+ setFrom('me@bar.com')->
17
+ setSubject('Subject goes here')->
18
+ setText('Hello World!')->
19
+ setHtml('<strong>Hello World!</strong>');
20
 
21
+ $sendgrid->send($email);
22
+ ```
23
 
24
+ ## Installation
25
 
26
+ Add SendGrid to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.
27
 
28
  ```json
29
+ {
30
  "require": {
31
+ "sendgrid/sendgrid": "2.2.0"
32
  }
33
  }
34
  ```
 
35
 
36
+ Then at the top of your PHP script require the autoloader:
 
 
37
 
38
  ```bash
39
+ require 'vendor/autoload.php';
40
  ```
41
 
42
+ #### Alternative: Install from zip
43
+
44
+ If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://sendgrid-open-source.s3.amazonaws.com/sendgrid-php/sendgrid-php.zip)**.
45
 
46
+ [**⬇︎ Download Packaged Library ⬇︎**](https://sendgrid-open-source.s3.amazonaws.com/sendgrid-php/sendgrid-php.zip)
47
+
48
+ Then require the library from package:
49
 
50
  ```php
51
+ require("path/to/sendgrid-php/sendgrid-php.php");
52
  ```
53
 
54
+ Previous versions of the library can be found in the [version index](https://sendgrid-open-source.s3.amazonaws.com/index.html).
55
 
56
+ ## Example App
57
 
58
+ There is a [sendgrid-php-example app](https://github.com/sendgrid/sendgrid-php-example) to help jumpstart your development.
59
 
60
+ ## Usage
61
+
62
+ To begin using this library, initialize the SendGrid object with your SendGrid credentials.
63
+
64
+ ```php
65
+ $sendgrid = new SendGrid('username', 'password');
66
  ```
67
 
68
+ Create a new SendGrid Email object and add your message details.
69
 
70
  ```php
71
+ $email = new SendGrid\Email();
72
+ $email->addTo('foo@bar.com')->
73
+ addTo('bar@foo.com')->
74
+ setFrom('me@bar.com')->
75
+ setSubject('Subject goes here')->
76
+ setText('Hello World!')->
77
+ setHtml('<strong>Hello World!</strong>');
78
  ```
79
 
80
+ Send it.
81
 
82
+ ```php
83
+ $sendgrid->send($email);
84
+ ```
85
 
86
+ #### addTo
87
+
88
+ You can add one or multiple TO addresses using `addTo`.
89
+
90
+ ```php
91
+ $email = new SendGrid\Email();
92
+ $email->addTo('foo@bar.com')->
93
+ addTo('another@another.com');
94
+ $sendgrid->send($email);
95
+ ```
96
+
97
+ #### setTos
98
+
99
+ If you prefer, you can add multiple TO addresses as an array using the `setTos` method. This will unset any previous `addTo`s you appended.
100
+
101
+ ```php
102
+ $email = new SendGrid\Email();
103
+ $emails = array("foo@bar.com", "another@another.com", "other@other.com");
104
+ $email->setTos($emails);
105
+ $sendgrid->send($email);
106
  ```
107
 
108
+ #### setFrom
109
 
110
+ ```php
111
+ $email = new SendGrid\Email();
112
+ $email->setFrom('foo@bar.com');
113
+ $sendgrid->send($email);
114
+ ```
115
 
116
+ #### setFromName
117
 
118
+ ```php
119
+ $email = new SendGrid\Email();
120
+ $email->setFrom('foo@bar.com');
121
+ $email->setFromName('Foo Bar');
122
+ $email->setFrom('other@example.com');
123
+ $email->setFromName('Other Guy');
124
+ $sendgrid->send($email);
125
  ```
126
 
127
+ #### setReplyTo
 
 
128
 
129
+ ```php
130
+ $email = new SendGrid\Email();
131
+ $email->addTo('foo@bar.com')->
132
+ setReplyTo('someone.else@example.com')->
133
+ setFromName('John Doe')->
134
+ ...
135
+ ```
136
 
137
+ ### Cc
138
 
139
+ #### addCc
140
 
141
+ ```php
142
+ $email = new SendGrid\Email();
143
+ $email->addCc('foo@bar.com');
144
+ $sendgrid->send($email);
145
+ ```
146
 
147
+ #### setCc
 
 
 
148
 
149
+ ```php
150
+ $email = new SendGrid\Email();
151
+ $email->setCc('foo@bar.com');
152
+ $sendgrid->send($email);
153
+ ```
154
 
155
+ #### setCcs
156
 
157
  ```php
158
+ $email = new SendGrid\Email();
159
+ $emails = array("foo@bar.com", "another@another.com", "other@other.com");
160
+ $email->setCcs($emails);
161
+ $sendgrid->send($email);
162
  ```
163
 
164
+ #### removeCc
165
 
166
  ```php
167
+ $email->removeCc('foo@bar.com');
168
+ ```
169
+
170
+ ### Bcc
171
+
172
+ Use multiple `addTo`s as a superior alternative to `setBcc`.
173
+
174
+ ```php
175
+ $email = new SendGrid\Email();
176
+ $email->addTo('foo@bar.com')->
177
+ addTo('someotheraddress@bar.com')->
178
+ addTo('another@another.com')->
179
+ ...
180
+ ```
181
+
182
+ But if you do still have a need for Bcc you can do the following:
183
+
184
+ #### addBcc
185
+
186
+ ```php
187
+ $email = new SendGrid\Email();
188
+ $email->addBcc('foo@bar.com');
189
+ $sendgrid->send($email);
190
+ ```
191
+
192
+ #### setBcc
193
+
194
+ ```php
195
+ $email = new SendGrid\Email();
196
+ $email->setBcc('foo@bar.com');
197
+ $sendgrid->send($email);
198
+ ```
199
+
200
+ #### setBccs
201
+
202
+ ```php
203
+ $email = new SendGrid\Email();
204
+ $emails = array("foo@bar.com", "another@another.com", "other@other.com");
205
+ $email->setBccs($emails);
206
+ $sendgrid->send($email);
207
+ ```
208
+
209
+ #### removeBcc
210
+
211
+ ```php
212
+ $email->removeBcc('foo@bar.com');
213
+ ```
214
+
215
+ #### setSubject
216
+
217
+ ```php
218
+ $email = new SendGrid\Email();
219
+ $email->setSubject('This is a subject');
220
+ $sendgrid->send($email);
221
+ ```
222
+
223
+ #### setText
224
+
225
+ ```php
226
+ $email = new SendGrid\Email();
227
+ $email->setText('This is some text');
228
+ $sendgrid->send($email);
229
  ```
230
 
231
+ #### setHtml
232
 
233
  ```php
234
+ $email = new SendGrid\Email();
235
+ $email->setHtml('<h1>This is an html email</h1>');
236
+ $sendgrid->send($email);
237
  ```
238
+
239
+ #### setDate
240
+
241
+ ```php
242
+ $email = new SendGrid\Email();
243
+ $email->setDate('Wed, 17 Dec 2014 19:21:16 +0000');
244
+ $sendgrid->send($email);
245
+ ```
246
+
247
+ #### setSendAt
248
+
249
+ ```php
250
+ $email = new SendGrid\Email();
251
+ $email->setSendAt(1409348513);
252
+ $sendgrid->send($email);
253
+ ```
254
+
255
+ #### setSendEachAt
256
 
257
  ```php
258
+ $email = new SendGrid\Email();
259
+ $email->setSendEachAt(array(1409348513, 1409348514, 1409348515));
260
+ $sendgrid->send($email);
261
  ```
262
 
263
+ #### addSendEachAt
264
+
265
+ ```php
266
+ $email = new SendGrid\Email();
267
+ $email->addSendEachAt(1409348513);
268
+ $email->addSendEachAt(1409348514);
269
+ $email->addSendEachAt(1409348515);
270
+ $sendgrid->send($email);
271
+ ```
272
+
273
+ ### Categories ###
274
 
275
  Categories are used to group email statistics provided by SendGrid.
276
 
277
  To use a category, simply set the category name. Note: there is a maximum of 10 categories per email.
278
 
279
+ #### addCategory
280
+
281
  ```php
282
+ $email = new SendGrid\Email();
283
+ $email->addTo('foo@bar.com')->
284
  ...
285
  addCategory("Category 1")->
286
  addCategory("Category 2");
287
  ```
288
 
289
+ #### setCategory
290
 
291
+ ```php
292
+ $email = new SendGrid\Email();
293
+ $email->addTo('foo@bar.com')->
294
+ ...
295
+ setCategory("Category 1");
296
+ ```
297
+
298
+ #### setCategories
299
+
300
+ ```php
301
+ $email = new SendGrid\Email();
302
+ $categories = array("Category 1", "Category 2", "Category 3");
303
+ $email->setCategories($categories);
304
+ ```
305
+
306
+ #### removeCategory
307
+
308
+ ```php
309
+ $email = new SendGrid\Email();
310
+ $email->addTo('foo@bar.com')->
311
+ ...
312
+ removeCategory("Category 1");
313
+ ```
314
+
315
+ ### Attachments ###
316
 
317
  Attachments are currently file based only, with future plans for an in memory implementation as well.
318
 
319
  File attachments are limited to 7 MB per file.
320
 
321
+ #### addAttachment
322
+
323
  ```php
324
+ $email = new SendGrid\Email();
325
+ $email->addTo('foo@bar.com')->
326
  ...
327
+ addAttachment("../path/to/file.txt");
328
  ```
329
 
330
+ #### setAttachment
331
 
332
+ ```php
333
+ $email = new SendGrid\Email();
334
+ $email->addTo('foo@bar.com')->
335
+ ...
336
+ setAttachment("../path/to/file.txt");
337
+ ```
338
+
339
+ #### setAttachments
340
 
341
  ```php
342
+ $email = new SendGrid\Email();
343
+ $attachments = array("../path/to/file1.txt", "../path/to/file2.txt");
344
+ $email->addTo('foo@bar.com')->
345
+ ...
346
+ setAttachments($attachments);
347
+ ```
348
+
349
+ #### removeAttachment
350
+
351
+ ```php
352
+ $email = new SendGrid\Email();
353
+ $email->addTo('foo@bar.com')->
354
  ...
355
+ addAttachment("../path/to/file.txt");
356
+ $email->removeAttachment("../path/to/file.txt");
357
+ ```
358
+
359
+ You can tag files for use as inline HTML content. It will mark the file for inline disposition using the specified "cid".
360
+
361
+ ```php
362
+ $email = new SendGrid\Email();
363
+ $email->addTo('foo@bar.com')
364
+ ->setHtml('<div>Our logo:<img src="cid:file-cid"></div>')
365
+ ->addAttachment("../path/to/file.txt", "super_file.txt", "file-cid");
366
  ```
367
 
368
+ **Important Gotcha**: `setBcc` is not supported with attachments. This is by design. Instead use multiple `addTo`s. Each user will receive their own personalized email with that setup, and only see their own email.
369
+
370
+
371
+ Standard `setBcc` will hide who the email is addressed to. If you use the multiple addTo, each user will receive a personalized email showing **only* their email. This is more friendly and more personal. Additionally, it is a good idea to use multiple `addTo`s because setBcc is not supported with attachments. This is by design.
372
+
373
+ So just remember, when thinking 'bcc', instead use multiple `addTo`s.
374
+
375
+ ### Substitutions ###
376
 
377
  Substitutions can be used to customize multi-recipient emails, and tailor them for the user
378
 
379
+ #### addSubstitution
380
+
381
  ```php
382
+ $email = new SendGrid\Email();
383
+ $email->addTo('john@somewhere.com')->
384
+ addTo('harry@somewhere.com')->
385
+ addTo('Bob@somewhere.com')->
386
  ...
387
+ setHtml('Hey %name%, we've seen that you've been gone for a while')->
388
+ addSubstitution('%name%', array('John', 'Harry', 'Bob'));
389
+ ```
390
+
391
+ Substitutions can also be used to customize multi-recipient subjects.
392
+
393
+ ```php
394
+ $email = new SendGrid\Email();
395
+ $email->addTos(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
396
+ ->setSubject('%subject%')
397
+ ->addSubstitution('%subject%', array('Subject to John', 'Subject to Harry', 'Subject to Bob'))
398
+ ...;
399
+ ```
400
+
401
+ #### setSubstitutions
402
+
403
+ ```php
404
+ $email = new SendGrid\Email();
405
+ $email->addTos(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
406
+ ->setSubject('%subject%')
407
+ ->setSubstitutions(array('%name%' => array('John', 'Harry', 'Bob') , '%subject%' => array('Subject to John', 'Subject to Harry', 'Subject to Bob')))
408
+ ...;
409
  ```
410
 
411
+ ### Sections ###
412
 
413
+ Sections can be used to further customize messages for the end users. A section is only useful in conjunction with a substitution value.
414
+
415
+ #### addSection
416
 
417
  ```php
418
+ $email = new SendGrid\Email();
419
+ $email->addTo('john@somewhere.com')->
420
  addTo("harry@somewhere.com")->
421
  addTo("Bob@somewhere.com")->
422
  ...
427
  addSection("%home%", "your house");
428
  ```
429
 
430
+ #### setSections
431
+
432
+ ```php
433
+ $email = new SendGrid\Email();
434
+ $email->addTo('john@somewhere.com')->
435
+ addTo("harry@somewhere.com")->
436
+ addTo("Bob@somewhere.com")->
437
+ ...
438
+ setHtml("Hey %name%, you work at %place%")->
439
+ addSubstitution("%name%", array("John", "Harry", "Bob"))->
440
+ addSubstitution("%place%", array("%office%", "%office%", "%home%"))->
441
+ setSections(array("%office%" => "an office", "%home%" => "your house"));
442
+ ```
443
+
444
+ ### Unique Arguments ###
445
 
446
  Unique Arguments are used for tracking purposes
447
 
448
+ #### addUniqueArg / addUniqueArgument
449
+
450
  ```php
451
+ $email = new SendGrid\Email();
452
+ $email->addTo('foo@bar.com')->
453
  ...
454
+ addUniqueArg("Customer", "Someone")->
455
+ addUniqueArg("location", "Somewhere")->
456
  ```
457
 
458
+ #### setUniqueArgs / setUniqueArguments
459
+
460
+ ```php
461
+ $email = new SendGrid\Email();
462
+ $email->addTo('foo@bar.com')->
463
+ ...
464
+ setUniqueArgs(array('cow' => 'chicken'));
465
+ ```
466
+
467
+ ### Filter Settings ###
468
 
469
  Filter Settings are used to enable and disable apps, and to pass parameters to those apps.
470
 
471
+ #### addFilter / addFilterSetting
472
+
473
+ ```php
474
+ $email = new SendGrid\Email();
475
+ $email->addTo('foo@bar.com')->
476
+ ...
477
+ addFilter("gravatar", "enable", 1)->
478
+ addFilter("footer", "enable", 1)->
479
+ addFilter("footer", "text/plain", "Here is a plain text footer")->
480
+ addFilter("footer", "text/html", "<p style='color:red;'>Here is an HTML footer</p>");
481
+ ```
482
+
483
+ #### setFilters / setFilterSettings
484
+
485
+ ```php
486
+ $email = new SendGrid\Email();
487
+ $email->addTo('foo@bar.com')->
488
+ ...
489
+ setFilters(array("gravatar" => array("settings" => array("enable" => 1))))
490
+ ```
491
+
492
+ ### Headers ###
493
+
494
+ You can add standard email message headers as necessary.
495
+
496
+ #### addHeader
497
+
498
  ```php
499
+ $email = new SendGrid\Email();
500
+ $email->addTo('foo@bar.com')->
501
  ...
502
+ addHeader('X-Sent-Using', 'SendGrid-API')->
503
+ addHeader('X-Transport', 'web');
 
 
504
  ```
505
 
506
+ #### setHeaders
507
+
508
+ ```php
509
+ $email = new SendGrid\Email();
510
+ $email->addTo('foo@bar.com')->
511
+ ...
512
+ setHeaders(array('X-Sent-Using' => 'SendGrid-API', 'X-Transport' => 'web'));
513
+ ```
514
 
515
+ #### removeHeader
516
 
517
  ```php
518
+ $email = new SendGrid\Email();
519
+ $email->addTo('foo@bar.com')->
520
  ...
521
+ addHeader('X-Sent-Using', 'SendGrid-API')->
522
+ addHeader('X-Transport', 'web');
523
+ $email->removeHeader('X-Transport');
524
+ ```
525
+
526
+ ### Options
527
+ Options may be passed to the library when initializing the SendGrid object:
528
+
529
+ ```php
530
+ $options = array(
531
+ 'turn_off_ssl_verification' => false,
532
+ 'protocol' => 'https',
533
+ 'host' => 'api.sendgrid.com',
534
+ 'endpoint' => '/api/mail.send.json',
535
+ 'port' => null,
536
+ 'url' => null
537
+ );
538
+ $sendgrid = new SendGrid('username', 'password', $options);
539
+ ```
540
+
541
+ #### Changing URL
542
+ You may change the URL sendgrid-php uses to send email by supplying various parameters to `options`, all parameters are optional:
543
+
544
+ ```php
545
+ $sendgrid = new SendGrid('username', 'password', array( 'protocol' => 'http', 'host' => 'sendgrid.org', 'endpoint' => '/send', 'port' => '80' ));
546
+ ```
547
+
548
+ A full URL may also be provided:
549
+
550
+ ```php
551
+ $sendgrid = new SendGrid('username', 'password', array( 'url' => 'http://sendgrid.org:80/send'));
552
+ ```
553
+
554
+ #### Ignoring SSL certificate verification
555
+
556
+ You can optionally ignore verification of SSL certificate when using the Web API.
557
+
558
+ ```php
559
+ $sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD, array("turn_off_ssl_verification" => true));
560
+ ```
561
+
562
+
563
+ ### Sending to 1,000s of emails in one batch
564
+
565
+ Sometimes you might want to send 1,000s of emails in one request. You can do that. It is recommended you break each batch up in 1,000 increments. So if you need to send to 5,000 emails, then you'd break this into a loop of 1,000 emails at a time.
566
+
567
+ ```php
568
+ $sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD);
569
+ $email = new SendGrid\Email();
570
+
571
+ $recipients = array("alpha@mailinator.com", "beta@mailinator.com", "zeta@mailinator.com");
572
+ $names = array("Alpha", "Beta", "Zeta");
573
+
574
+ $email->setFrom("from@mailinator.com")->
575
+ setSubject('[sendgrid-php-batch-email]')->
576
+ setTos($recipients)->
577
+ addSubstitution("%name%", $names)->
578
+ setText("Hey %name, we have an email for you")->
579
+ setHtml("<h1>Hey %name%, we have an email for you</h1>");
580
+
581
+ $result = $sendgrid->send($email);
582
+ ```
583
+
584
+
585
+ ## Contributing
586
+
587
+ 1. Fork it
588
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
589
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
590
+ 4. Push to the branch (`git push origin my-new-feature`)
591
+ 5. Create new Pull Request
592
+
593
+ ## Running Tests
594
+
595
+ The existing tests in the `test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:
596
+
597
+ ````bash
598
+ composer update --dev
599
+ cd test
600
+ ../vendor/bin/phpunit
601
+ ```
602
+
603
+ or if you already have PHPUnit installed globally.
604
+
605
+ ```bash
606
+ cd test
607
+ phpunit
608
+ ```
609
+
610
+ ## Releasing
611
+
612
+ To release a new version of this library, update the version in all locations, tag the version, and then push the tag up. Packagist.org takes care of the rest.
613
+
614
+ #### Testing uploading to Amazon S3
615
+
616
+ If you want to test uploading the zipped file to Amazon S3 (SendGrid employees only), do the following.
617
+
618
  ```
619
+ export S3_SIGNATURE="secret_signature"
620
+ export S3_POLICY="secret_policy"
621
+ export S3_BUCKET="sendgrid-open-source"
622
+ export S3_ACCESS_KEY="secret_access_key"
623
+ ./scripts/s3upload.sh
624
+ ```
625
+
626
+
627
+
628
+
vendor/sendgrid-php/SendGrid.php DELETED
@@ -1,44 +0,0 @@
1
- <?php
2
-
3
- class SendGrid
4
- {
5
- const VERSION = "1.0.0";
6
-
7
- protected $namespace = "SendGrid",
8
- $username,
9
- $password;
10
-
11
- // Available transport mechanisms
12
- protected $web,
13
- $smtp;
14
-
15
- public function __construct($username, $password)
16
- {
17
- $this->username = $username;
18
- $this->password = $password;
19
- }
20
-
21
- public function __get($api)
22
- {
23
- $name = $api;
24
-
25
- if($this->$name != null)
26
- {
27
- return $this->$name;
28
- }
29
-
30
- $api = $this->namespace . "\\" . ucwords($api);
31
- $class_name = str_replace('\\', '/', "$api.php");
32
- $file = __dir__ . DIRECTORY_SEPARATOR . $class_name;
33
-
34
- if (!file_exists($file))
35
- {
36
- throw new Exception("Api '$class_name' not found.");
37
- }
38
- require_once $file;
39
-
40
- $this->$name = new $api($this->username, $this->password);
41
- return $this->$name;
42
- }
43
-
44
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/SendGrid/Api.php DELETED
@@ -1,17 +0,0 @@
1
- <?php
2
-
3
- namespace SendGrid;
4
-
5
- class Api
6
- {
7
-
8
- protected $username,
9
- $password;
10
-
11
- public function __construct($username, $password)
12
- {
13
- $this->username = $username;
14
- $this->password = $password;
15
- }
16
-
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/SendGrid/Mail.php DELETED
@@ -1,721 +0,0 @@
1
- <?php
2
-
3
- namespace SendGrid;
4
-
5
- class Mail
6
- {
7
-
8
- private $to_list,
9
- $from,
10
- $from_name,
11
- $reply_to,
12
- $cc_list,
13
- $bcc_list,
14
- $subject,
15
- $text,
16
- $html,
17
- $attachment_list,
18
- $header_list = array();
19
-
20
- protected $use_headers;
21
-
22
- public function __construct()
23
- {
24
- $this->from_name = false;
25
- $this->reply_to = false;
26
- }
27
-
28
- /**
29
- * _removeFromList
30
- * Given a list of key/value pairs, removes the associated keys
31
- * where a value matches the given string ($item)
32
- * @param Array $list - the list of key/value pairs
33
- * @param String $item - the value to be removed
34
- */
35
- private function _removeFromList(&$list, $item, $key_field = null)
36
- {
37
- foreach ($list as $key => $val)
38
- {
39
- if($key_field)
40
- {
41
- if($val[$key_field] == $item)
42
- {
43
- unset($list[$key]);
44
- }
45
- }
46
- else
47
- {
48
- if ($val == $item)
49
- {
50
- unset($list[$key]);
51
- }
52
- }
53
- }
54
- //repack the indices
55
- $list = array_values($list);
56
- }
57
-
58
- /**
59
- * getTos
60
- * Return the list of recipients
61
- * @return list of recipients
62
- */
63
- public function getTos()
64
- {
65
- return $this->to_list;
66
- }
67
-
68
- /**
69
- * setTos
70
- * Initialize an array for the recipient 'to' field
71
- * Destroy previous recipient 'to' data.
72
- * @param Array $email_list - an array of email addresses
73
- * @return the SendGrid\Mail object.
74
- */
75
- public function setTos(array $email_list)
76
- {
77
- $this->to_list = $email_list;
78
- return $this;
79
- }
80
-
81
- /**
82
- * setTo
83
- * Initialize a single email for the recipient 'to' field
84
- * Destroy previous recipient 'to' data.
85
- * @param String $email - a list of email addresses
86
- * @return the SendGrid\Mail object.
87
- */
88
- public function setTo($email)
89
- {
90
- $this->to_list = array($email);
91
- return $this;
92
- }
93
-
94
- /**
95
- * addTo
96
- * append an email address to the existing list of addresses
97
- * Preserve previous recipient 'to' data.
98
- * @param String $email - a single email address
99
- * @return the SendGrid\Mail object.
100
- */
101
- public function addTo($email, $name=null)
102
- {
103
- $this->to_list[] = ($name ? $name . "<" . $email . ">" : $email);
104
-
105
- return $this;
106
- }
107
-
108
- /**
109
- * removeTo
110
- * remove an email address from the list of recipient addresses
111
- * @param String $search_term - the regex value to be removed
112
- * @return the SendGrid\Mail object.
113
- */
114
- public function removeTo($search_term)
115
- {
116
- $this->to_list = array_values(array_filter($this->to_list, function($item) use($search_term) {
117
- return !preg_match("/" . $search_term . "/", $item);
118
- }));
119
- return $this;
120
- }
121
-
122
- /**
123
- * getFrom
124
- * get the from email address
125
- * @param Boolean $as_array - return the from as an assocative array
126
- * @return the from email address
127
- */
128
- public function getFrom($as_array = false)
129
- {
130
- if($as_array && ($name = $this->getFromName())) {
131
- return array("$this->from" => $name);
132
- } else {
133
- return $this->from;
134
- }
135
- }
136
-
137
- /**
138
- * setFrom
139
- * set the from email
140
- * @param String $email - an email address
141
- * @return the SendGrid\Mail object.
142
- */
143
- public function setFrom($email)
144
- {
145
- $this->from = $email;
146
- return $this;
147
- }
148
-
149
- /**
150
- * getFromName
151
- * get the from name
152
- * @return the from name
153
- */
154
- public function getFromName()
155
- {
156
- return $this->from_name;
157
- }
158
-
159
- /**
160
- * setFromName
161
- * set the name appended to the from email
162
- * @param String $name - a name to append
163
- * @return the SendGrid\Mail object.
164
- */
165
- public function setFromName($name)
166
- {
167
- $this->from_name = $name;
168
- return $this;
169
- }
170
-
171
- /**
172
- * getReplyTo
173
- * get the reply-to address
174
- * @return the reply to address
175
- */
176
- public function getReplyTo()
177
- {
178
- return $this->reply_to;
179
- }
180
-
181
- /**
182
- * setReplyTo
183
- * set the reply-to address
184
- * @param String $email - the email to reply to
185
- * @return the SendGrid\Mail object.
186
- */
187
- public function setReplyTo($email)
188
- {
189
- $this->reply_to = $email;
190
- return $this;
191
- }
192
- /**
193
- * getCc
194
- * get the Carbon Copy list of recipients
195
- * @return Array the list of recipients
196
- */
197
- public function getCcs()
198
- {
199
- return $this->cc_list;
200
- }
201
-
202
- /**
203
- * setCcs
204
- * Set the list of Carbon Copy recipients
205
- * @param String $email - a list of email addresses
206
- * @return the SendGrid\Mail object.
207
- */
208
- public function setCcs(array $email_list)
209
- {
210
- $this->cc_list = $email_list;
211
- return $this;
212
- }
213
-
214
- /**
215
- * setCc
216
- * Initialize the list of Carbon Copy recipients
217
- * destroy previous recipient data
218
- * @param String $email - a list of email addresses
219
- * @return the SendGrid\Mail object.
220
- */
221
- public function setCc($email)
222
- {
223
- $this->cc_list = array($email);
224
- return $this;
225
- }
226
-
227
- /**
228
- * addCc
229
- * Append an address to the list of Carbon Copy recipients
230
- * @param String $email - an email address
231
- * @return the SendGrid\Mail object.
232
- */
233
- public function addCc($email)
234
- {
235
- $this->cc_list[] = $email;
236
- return $this;
237
- }
238
-
239
- /**
240
- * removeCc
241
- * remove an address from the list of Carbon Copy recipients
242
- * @param String $email - an email address
243
- * @return the SendGrid\Mail object.
244
- */
245
- public function removeCc($email)
246
- {
247
- $this->_removeFromList($this->cc_list, $email);
248
-
249
- return $this;
250
- }
251
-
252
- /**
253
- * getBccs
254
- * return the list of Blind Carbon Copy recipients
255
- * @return Array - the list of Blind Carbon Copy recipients
256
- */
257
- public function getBccs()
258
- {
259
- return $this->bcc_list;
260
- }
261
-
262
- /**
263
- * setBccs
264
- * set the list of Blind Carbon Copy Recipients
265
- * @param Array $email_list - the list of email recipients to
266
- * @return the SendGrid\Mail object.
267
- */
268
- public function setBccs($email_list)
269
- {
270
- $this->bcc_list = $email_list;
271
- return $this;
272
- }
273
-
274
- /**
275
- * setBcc
276
- * Initialize the list of Carbon Copy recipients
277
- * destroy previous recipient Blind Carbon Copy data
278
- * @param String $email - an email address
279
- * @return the SendGrid\Mail object.
280
- */
281
- public function setBcc($email)
282
- {
283
- $this->bcc_list = array($email);
284
- return $this;
285
- }
286
-
287
- /**
288
- * addBcc
289
- * Append an email address to the list of Blind Carbon Copy
290
- * recipients
291
- * @param String $email - an email address
292
- */
293
- public function addBcc($email)
294
- {
295
- $this->bcc_list[] = $email;
296
- return $this;
297
- }
298
-
299
- /**
300
- * removeBcc
301
- * remove an email address from the list of Blind Carbon Copy
302
- * addresses
303
- * @param String $email - the email to remove
304
- * @return the SendGrid\Mail object.
305
- */
306
- public function removeBcc($email)
307
- {
308
- $this->_removeFromList($this->bcc_list, $email);
309
- return $this;
310
- }
311
-
312
- /**
313
- * getSubject
314
- * get the email subject
315
- * @return the email subject
316
- */
317
- public function getSubject()
318
- {
319
- return $this->subject;
320
- }
321
-
322
- /**
323
- * setSubject
324
- * set the email subject
325
- * @param String $subject - the email subject
326
- * @return the SendGrid\Mail object
327
- */
328
- public function setSubject($subject)
329
- {
330
- $this->subject = $subject;
331
- return $this;
332
- }
333
-
334
- /**
335
- * getText
336
- * get the plain text part of the email
337
- * @return the plain text part of the email
338
- */
339
- public function getText()
340
- {
341
- return $this->text;
342
- }
343
-
344
- /**
345
- * setText
346
- * Set the plain text part of the email
347
- * @param String $text - the plain text of the email
348
- * @return the SendGrid\Mail object.
349
- */
350
- public function setText($text)
351
- {
352
- $this->text = $text;
353
- return $this;
354
- }
355
-
356
- /**
357
- * getHtml
358
- * Get the HTML part of the email
359
- * @param String $html - the HTML part of the email
360
- * @return the HTML part of the email.
361
- */
362
- public function getHtml()
363
- {
364
- return $this->html;
365
- }
366
-
367
- /**
368
- * setHTML
369
- * Set the HTML part of the email
370
- * @param String $html - the HTML part of the email
371
- * @return the SendGrid\Mail object.
372
- */
373
- public function setHtml($html)
374
- {
375
- $this->html = $html;
376
- return $this;
377
- }
378
-
379
- /**
380
- * getAttachments
381
- * Get the list of file attachments
382
- * @return Array of indexed file attachments
383
- */
384
- public function getAttachments()
385
- {
386
- return $this->attachment_list;
387
- }
388
-
389
- /**
390
- * setAttachments
391
- * add multiple file attachments at once
392
- * destroys previous attachment data.
393
- * @param array $files - The list of files to attach
394
- * @return the SendGrid\Mail object
395
- */
396
- public function setAttachments(array $files)
397
- {
398
- $this->attachment_list = array();
399
- foreach($files as $file)
400
- {
401
- $this->addAttachment($file);
402
- }
403
-
404
- return $this;
405
- }
406
-
407
- /**
408
- * setAttachment
409
- * Initialize the list of attachments, and add the given file
410
- * destroys previous attachment data.
411
- * @param String $file - the file to attach
412
- * @return the SendGrid\Mail object.
413
- */
414
- public function setAttachment($file)
415
- {
416
- $this->attachment_list = array($this->_getAttachmentInfo($file));
417
- return $this;
418
- }
419
-
420
- /**
421
- * addAttachment
422
- * Add a new email attachment, given the file name.
423
- * @param String $file - The file to attach.
424
- * @return the SendGrid\Mail object.
425
- */
426
- public function addAttachment($file)
427
- {
428
- $this->attachment_list[] = $this->_getAttachmentInfo($file);
429
- return $this;
430
- }
431
-
432
- /**
433
- * removeAttachment
434
- * Remove a previously added file attachment, given the file name.
435
- * @param String $file - the file attachment to remove.
436
- * @return the SendGrid\Mail object.
437
- */
438
- public function removeAttachment($file)
439
- {
440
- $this->_removeFromList($this->attachment_list, $file, "file");
441
- return $this;
442
- }
443
-
444
- private function _getAttachmentInfo($file)
445
- {
446
- $info = pathinfo($file);
447
- $info['file'] = $file;
448
- return $info;
449
- }
450
-
451
- /**
452
- * setCategories
453
- * Set the list of category headers
454
- * destroys previous category header data
455
- * @param Array $category_list - the list of category values
456
- * @return the SendGrid\Mail object.
457
- */
458
- public function setCategories($category_list)
459
- {
460
- $this->header_list['category'] = $category_list;
461
- return $this;
462
- }
463
-
464
- /**
465
- * setCategory
466
- * Clears the category list and adds the given category
467
- * @param String $category - the new category to append
468
- * @return the SendGrid\Mail object.
469
- */
470
- public function setCategory($category)
471
- {
472
- $this->header_list['category'] = array($category);
473
- return $this;
474
- }
475
-
476
- /**
477
- * addCategory
478
- * Append a category to the list of categories
479
- * @param String $category - the new category to append
480
- * @return the SendGrid\Mail object.
481
- */
482
- public function addCategory($category)
483
- {
484
- $this->header_list['category'][] = $category;
485
- return $this;
486
- }
487
-
488
- /**
489
- * removeCategory
490
- * Given a category name, remove that category from the list
491
- * of category headers
492
- * @param String $category - the category to be removed
493
- * @return the SendGrid\Mail object.
494
- */
495
- public function removeCategory($category)
496
- {
497
- $this->_removeFromList($this->header_list['category'], $category);
498
- return $this;
499
- }
500
-
501
- /**
502
- * SetSubstitutions
503
- *
504
- * Substitute a value for list of values, where each value corresponds
505
- * to the list emails in a one to one relationship. (IE, value[0] = email[0],
506
- * value[1] = email[1])
507
- *
508
- * @param array $key_value_pairs - key/value pairs where the value is an array of values
509
- * @return the SendGrid\Mail object.
510
- */
511
- public function setSubstitutions($key_value_pairs)
512
- {
513
- $this->header_list['sub'] = $key_value_pairs;
514
- return $this;
515
- }
516
-
517
- /**
518
- * addSubstitution
519
- * Substitute a value for list of values, where each value corresponds
520
- * to the list emails in a one to one relationship. (IE, value[0] = email[0],
521
- * value[1] = email[1])
522
- *
523
- * @param string $from_key - the value to be replaced
524
- * @param array $to_values - an array of values to replace the $from_value
525
- * @return the SendGrid\Mail object.
526
- */
527
- public function addSubstitution($from_value, array $to_values)
528
- {
529
- $this->header_list['sub'][$from_value] = $to_values;
530
- return $this;
531
- }
532
-
533
- /**
534
- * setSection
535
- * Set a list of section values
536
- * @param Array $key_value_pairs
537
- * @return the SendGrid\Mail object.
538
- */
539
- public function setSections(array $key_value_pairs)
540
- {
541
- $this->header_list['section'] = $key_value_pairs;
542
- return $this;
543
- }
544
-
545
- /**
546
- * addSection
547
- * append a section value to the list of section values
548
- * @param String $from_value - the value to be replaced
549
- * @param String $to_value - the value to replace
550
- * @return the SendGrid\Mail object.
551
- */
552
- public function addSection($from_value, $to_value)
553
- {
554
- $this->header_list['section'][$from_value] = $to_value;
555
- return $this;
556
- }
557
-
558
- /**
559
- * setUniqueArguments
560
- * Set a list of unique arguments, to be used for tracking purposes
561
- * @param array $key_value_pairs - list of unique arguments
562
- */
563
- public function setUniqueArguments(array $key_value_pairs)
564
- {
565
- $this->header_list['unique_args'] = $key_value_pairs;
566
- return $this;
567
- }
568
-
569
- /**
570
- * addUniqueArgument
571
- * Set a key/value pair of unique arguments, to be used for tracking purposes
572
- * @param string $key - key
573
- * @param string $value - value
574
- */
575
- public function addUniqueArgument($key, $value)
576
- {
577
- $this->header_list['unique_args'][$key] = $value;
578
- return $this;
579
- }
580
-
581
- /**
582
- * setFilterSettings
583
- * Set filter/app settings
584
- * @param array $filter_settings - array of fiter settings
585
- */
586
- public function setFilterSettings($filter_settings)
587
- {
588
- $this->header_list['filters'] = $filter_settings;
589
- return $this;
590
- }
591
-
592
- /**
593
- * addFilterSetting
594
- * Append a filter setting to the list of filter settings
595
- * @param string $filter_name - filter name
596
- * @param string $parameter_name - parameter name
597
- * @param string $parameter_value - setting value
598
- */
599
- public function addFilterSetting($filter_name, $parameter_name, $parameter_value)
600
- {
601
- $this->header_list['filters'][$filter_name]['settings'][$parameter_name] = $parameter_value;
602
- return $this;
603
- }
604
-
605
- /**
606
- * getHeaders
607
- * return the list of headers
608
- * @return Array the list of headers
609
- */
610
- public function getHeaders()
611
- {
612
- return $this->header_list;
613
- }
614
-
615
- /**
616
- * getHeaders
617
- * return the list of headers
618
- * @return Array the list of headers
619
- */
620
- public function getHeadersJson()
621
- {
622
- if (count($this->getHeaders()) <= 0)
623
- {
624
- return "{}";
625
- }
626
- return json_encode($this->getHeaders(), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
627
- }
628
-
629
- /**
630
- * setHeaders
631
- * Sets the list headers
632
- * destroys previous header data
633
- * @param Array $key_value_pairs - the list of header data
634
- * @return the SendGrid\Mail object.
635
- */
636
- public function setHeaders($key_value_pairs)
637
- {
638
- $this->header_list = $key_value_pairs;
639
- return $this;
640
- }
641
-
642
- /**
643
- * addHeaders
644
- * append the header to the list of headers
645
- * @param String $key - the header key
646
- * @param String $value - the header value
647
- */
648
- public function addHeader($key, $value)
649
- {
650
- $this->header_list[$key] = $value;
651
- return $this;
652
- }
653
-
654
- /**
655
- * removeHeaders
656
- * remove a header key
657
- * @param String $key - the key to remove
658
- * @return the SendGrid\Mail object.
659
- */
660
- public function removeHeader($key)
661
- {
662
- unset($this->header_list[$key]);
663
- return $this;
664
- }
665
-
666
- /**
667
- * useHeaders
668
- * Checks to see whether or not we can or should you headers. In most cases,
669
- * we prefer to send our recipients through the headers, but in some cases,
670
- * we actually don't want to. However, there are certain circumstances in
671
- * which we have to.
672
- */
673
- public function useHeaders()
674
- {
675
- return !($this->_preferNotToUseHeaders() && !$this->_isHeadersRequired());
676
- }
677
-
678
- public function setRecipientsInHeader($preference)
679
- {
680
- $this->use_headers = $preference;
681
-
682
- return $this;
683
- }
684
-
685
- /**
686
- * isHeaderRequired
687
- * determines whether or not we need to force recipients through the smtpapi headers
688
- * @return boolean, if true headers are required
689
- */
690
- protected function _isHeadersRequired()
691
- {
692
- if(count($this->getAttachments()) > 0 || $this->use_headers )
693
- {
694
- return true;
695
- }
696
- return false;
697
- }
698
-
699
- /**
700
- * _preferNotToUseHeaders
701
- * There are certain cases in which headers are not a preferred choice
702
- * to send email, as it limits some basic email functionality. Here, we
703
- * check for any of those rules, and add them in to decide whether or
704
- * not to use headers
705
- * @return boolean, if true we don't
706
- */
707
- protected function _preferNotToUseHeaders()
708
- {
709
- if (count($this->getBccs()) > 0 || count($this->getCcs()) > 0)
710
- {
711
- return true;
712
- }
713
- if ($this->use_headers !== null && !$this->use_headers)
714
- {
715
- return true;
716
- }
717
-
718
- return false;
719
- }
720
-
721
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/SendGrid/MailInterface.php DELETED
@@ -1,10 +0,0 @@
1
- <?php
2
-
3
- namespace SendGrid;
4
-
5
- interface MailInterface
6
- {
7
- public function send(Mail $mail);
8
-
9
-
10
- }
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/SendGrid/Web.php DELETED
@@ -1,147 +0,0 @@
1
- <?php
2
-
3
- namespace SendGrid;
4
-
5
- class Web extends Api implements MailInterface
6
- {
7
-
8
- protected $domain = "http://sendgrid.com/";
9
- protected $endpoint = "api/mail.send.json";
10
-
11
- /**
12
- * __construct
13
- * Create a new Web instance
14
- */
15
- public function __construct($username, $password)
16
- {
17
- call_user_func_array("parent::__construct", func_get_args());
18
- }
19
-
20
- /**
21
- * _prepMessageData
22
- * Takes the mail message and returns a url friendly querystring
23
- * @param Mail $mail [description]
24
- * @return String - the data query string to be posted
25
- */
26
- protected function _prepMessageData(Mail $mail)
27
- {
28
-
29
- /* the api expects a 'to' parameter, but this parameter will be ignored
30
- * since we're sending the recipients through the header. The from
31
- * address will be used as a placeholder.
32
- */
33
- $params =
34
- array(
35
- 'api_user' => $this->username,
36
- 'api_key' => $this->password,
37
- 'subject' => $mail->getSubject(),
38
- 'from' => $mail->getFrom(),
39
- 'to' => $mail->getFrom(),
40
- 'x-smtpapi' => $mail->getHeadersJson()
41
- );
42
-
43
- if($mail->getHtml()) {
44
- $params['html'] = $mail->getHtml();
45
- }
46
-
47
- if($mail->getText()) {
48
- $params['text'] = $mail->getText();
49
- }
50
-
51
- if(($fromname = $mail->getFromName())) {
52
- $params['fromname'] = $fromname;
53
- }
54
-
55
- if(($replyto = $mail->getReplyTo())) {
56
- $params['replyto'] = $replyto;
57
- }
58
-
59
- // determine if we should send our recipients through our headers,
60
- // and set the properties accordingly
61
- if($mail->useHeaders())
62
- {
63
- // workaround for posting recipients through SendGrid headers
64
- $headers = $mail->getHeaders();
65
- $headers['to'] = $mail->getTos();
66
- $mail->setHeaders($headers);
67
-
68
- $params['x-smtpapi'] = $mail->getHeadersJson();
69
- }
70
- else
71
- {
72
- $params['to'] = $mail->getTos();
73
- }
74
-
75
-
76
- if($mail->getAttachments())
77
- {
78
- foreach($mail->getAttachments() as $attachment)
79
- {
80
- $params['files['.$attachment['filename'].'.'.$attachment['extension'].']'] = '@'.$attachment['file'];
81
- }
82
- }
83
-
84
- return $params;
85
- }
86
-
87
- /**
88
- * _arrayToUrlPart
89
- * Converts an array to a url friendly string
90
- * @param array $array - the array to convert
91
- * @param String $token - the name of parameter
92
- * @return String - a url part that can be concatenated to a url request
93
- */
94
- protected function _arrayToUrlPart($array, $token)
95
- {
96
- $string = "";
97
-
98
- if ($array)
99
- {
100
- foreach ($array as $value)
101
- {
102
- $string.= "&" . $token . "[]=" . urlencode($value);
103
- }
104
- }
105
-
106
- return $string;
107
- }
108
-
109
- /**
110
- * send
111
- * Send an email
112
- * @param Mail $mail - The message to send
113
- * @return String the json response
114
- */
115
- public function send(Mail $mail)
116
- {
117
- $data = $this->_prepMessageData($mail);
118
-
119
- //if we're not using headers, we need to send a url friendly post
120
- if(!$mail->useHeaders())
121
- {
122
- $data = http_build_query($data);
123
- }
124
-
125
- $request = $this->domain . $this->endpoint;
126
-
127
- // we'll append the Bcc and Cc recipients to the url endpoint (GET)
128
- // so that we can still post attachments (via cURL array).
129
- $request.= "?" .
130
- substr($this->_arrayToUrlPart($mail->getBccs(), "bcc"), 1) .
131
- $this->_arrayToUrlPart($mail->getCcs(), "cc");
132
-
133
- $session = curl_init($request);
134
- curl_setopt($session, CURLOPT_POST, true);
135
- curl_setopt($session, CURLOPT_POSTFIELDS, $data);
136
- curl_setopt($session, CURLOPT_HEADER, false);
137
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
138
- curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 5);
139
- curl_setopt($session, CURLOPT_TIMEOUT, 30);
140
-
141
- // obtain response
142
- $response = curl_exec($session);
143
- curl_close($session);
144
-
145
- return $response;
146
- }
147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/SendGrid_loader.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- define("ROOT_DIR", __dir__ . DIRECTORY_SEPARATOR);
4
-
5
- function sendGridLoader($string)
6
- {
7
- if(preg_match("/SendGrid/", $string))
8
- {
9
- $file = str_replace('\\', '/', "$string.php");
10
- require_once ROOT_DIR . $file;
11
- }
12
- }
13
-
14
- spl_autoload_register("sendGridLoader");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/Mock/Mock_loader.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- define("MOCK_ROOT", __dir__ . DIRECTORY_SEPARATOR);
4
-
5
- function mockLoader($string)
6
- {
7
- if(preg_match("/Mock/", $string))
8
- {
9
- $file = str_replace('\\', '/', "$string.php");
10
- require_once MOCK_ROOT . $file;
11
- }
12
- }
13
-
14
- spl_autoload_register("mockLoader");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/Mock/SmtpMock.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- class SmtpMock extends SendGrid\Smtp
4
- {
5
- public function __construct($username, $password)
6
- {
7
- parent::__construct($username, $password);
8
- }
9
-
10
- public function getPort()
11
- {
12
- return $this->port;
13
- }
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/Mock/WebMock.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class WebMock extends SendGrid\Web
4
- {
5
- public function __construct($username, $password)
6
- {
7
- parent::__construct($username, $password);
8
- }
9
-
10
- public function testPrepMessageData(SendGrid\Mail $mail)
11
- {
12
- return $this->_prepMessageData($mail);
13
- }
14
-
15
- public function testArrayToUrlPart($array, $token)
16
- {
17
- return $this->_arrayToUrlPart($array, $token);
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/SendGrid/ApiTest.php DELETED
File without changes
vendor/sendgrid-php/Test/SendGrid/MailTest.php DELETED
@@ -1,549 +0,0 @@
1
- <?php
2
-
3
-
4
- class MailTest extends PHPUnit_Framework_TestCase
5
- {
6
-
7
- public function testToAccessors()
8
- {
9
- $message = new SendGrid\Mail();
10
-
11
- // setTo instanciates and overrides existing data
12
- $message->setTo('bar');
13
- $message->setTo('foo');
14
-
15
- $this->assertEquals(1, count($message->getTos()));
16
-
17
- $to_list = $message->getTos();
18
-
19
- $this->assertEquals('foo', $to_list[0]);
20
-
21
-
22
- // setTos instanciates and overrides existing data
23
- $message->setTos(array('raz', 'ber'));
24
-
25
- $this->assertEquals(2, count($message->getTos()));
26
-
27
- $to_list = $message->getTos();
28
-
29
- $this->assertEquals('raz', $to_list[0]);
30
- $this->assertEquals('ber', $to_list[1]);
31
-
32
- // addTo appends to existing data
33
- $message->addTo('foo');
34
- $message->addTo('raz');
35
-
36
- $this->assertEquals(4, count($message->getTos()));
37
-
38
- $to_list = $message->getTos();
39
-
40
- $this->assertEquals('raz', $to_list[0]);
41
- $this->assertEquals('ber', $to_list[1]);
42
- $this->assertEquals('foo', $to_list[2]);
43
- $this->assertEquals('raz', $to_list[3]);
44
-
45
- // removeTo removes all occurences of data
46
- $message->removeTo('raz');
47
-
48
- $this->assertEquals(2, count($message->getTos()));
49
-
50
- $to_list = $message->getTos();
51
-
52
- $this->assertEquals('ber', $to_list[0]);
53
- $this->assertEquals('foo', $to_list[1]);
54
- }
55
-
56
- public function testFromAccessors()
57
- {
58
- $message = new SendGrid\Mail();
59
-
60
- $message->setFrom("foo@bar.com");
61
- $message->setFromName("John Doe");
62
-
63
- $this->assertEquals("foo@bar.com", $message->getFrom());
64
- $this->assertEquals(array("foo@bar.com" => "John Doe"), $message->getFrom(true));
65
- }
66
-
67
- public function testFromNameAccessors()
68
- {
69
- $message = new SendGrid\Mail();
70
-
71
- // Defaults to false
72
- $this->assertFalse($message->getFromName());
73
-
74
- $message->setFromName("Swift");
75
-
76
- $this->assertEquals("Swift", $message->getFromName());
77
- }
78
-
79
- public function testReplyToAccessors()
80
- {
81
- $message = new SendGrid\Mail();
82
-
83
- // Defaults to false
84
- $this->assertFalse($message->getReplyTo());
85
-
86
- $message->setReplyTo("swift@sendgrid.com");
87
-
88
- $this->assertEquals("swift@sendgrid.com", $message->getReplyTo());
89
- }
90
-
91
- public function testCcAccessors()
92
- {
93
- $message = new SendGrid\Mail();
94
-
95
- // setTo instanciates and overrides existing data
96
- $message->setCc('bar');
97
- $message->setCc('foo');
98
-
99
- $this->assertEquals(1, count($message->getCcs()));
100
-
101
- $cc_list = $message->getCcs();
102
-
103
- $this->assertEquals('foo', $cc_list[0]);
104
-
105
-
106
- // setTos instanciates and overrides existing data
107
- $message->setCcs(array('raz', 'ber'));
108
-
109
- $this->assertEquals(2, count($message->getCcs()));
110
-
111
- $cc_list = $message->getCcs();
112
-
113
- $this->assertEquals('raz', $cc_list[0]);
114
- $this->assertEquals('ber', $cc_list[1]);
115
-
116
- // addTo appends to existing data
117
- $message->addCc('foo');
118
- $message->addCc('raz');
119
-
120
- $this->assertEquals(4, count($message->getCcs()));
121
-
122
- $cc_list = $message->getCcs();
123
-
124
- $this->assertEquals('raz', $cc_list[0]);
125
- $this->assertEquals('ber', $cc_list[1]);
126
- $this->assertEquals('foo', $cc_list[2]);
127
- $this->assertEquals('raz', $cc_list[3]);
128
-
129
- // removeTo removes all occurences of data
130
- $message->removeCc('raz');
131
-
132
- $this->assertEquals(2, count($message->getCcs()));
133
-
134
- $cc_list = $message->getCcs();
135
-
136
- $this->assertEquals('ber', $cc_list[0]);
137
- $this->assertEquals('foo', $cc_list[1]);
138
- }
139
-
140
- public function testBccAccessors()
141
- {
142
- $message = new SendGrid\Mail();
143
-
144
- // setTo instanciates and overrides existing data
145
- $message->setBcc('bar');
146
- $message->setBcc('foo');
147
-
148
- $this->assertEquals(1, count($message->getBccs()));
149
-
150
- $bcc_list = $message->getBccs();
151
-
152
- $this->assertEquals('foo', $bcc_list[0]);
153
-
154
-
155
- // setTos instanciates and overrides existing data
156
- $message->setBccs(array('raz', 'ber'));
157
-
158
- $this->assertEquals(2, count($message->getBccs()));
159
-
160
- $bcc_list = $message->getBccs();
161
-
162
- $this->assertEquals('raz', $bcc_list[0]);
163
- $this->assertEquals('ber', $bcc_list[1]);
164
-
165
- // addTo appends to existing data
166
- $message->addBcc('foo');
167
- $message->addBcc('raz');
168
-
169
- $this->assertEquals(4, count($message->getBccs()));
170
-
171
- $bcc_list = $message->getBccs();
172
-
173
- $this->assertEquals('raz', $bcc_list[0]);
174
- $this->assertEquals('ber', $bcc_list[1]);
175
- $this->assertEquals('foo', $bcc_list[2]);
176
- $this->assertEquals('raz', $bcc_list[3]);
177
-
178
- // removeTo removes all occurences of data
179
- $message->removeBcc('raz');
180
-
181
- $this->assertEquals(2, count($message->getBccs()));
182
-
183
- $bcc_list = $message->getBccs();
184
-
185
- $this->assertEquals('ber', $bcc_list[0]);
186
- $this->assertEquals('foo', $bcc_list[1]);
187
- }
188
-
189
- public function testSubjectAccessors()
190
- {
191
- $message = new SendGrid\Mail();
192
-
193
- $message->setSubject("Test Subject");
194
-
195
- $this->assertEquals("Test Subject", $message->getSubject());
196
- }
197
-
198
- public function testTextAccessors()
199
- {
200
- $message = new SendGrid\Mail();
201
-
202
- $text = "sample plain text";
203
-
204
- $message->setText($text);
205
-
206
- $this->assertEquals($text, $message->getText());
207
- }
208
-
209
- public function testHTMLAccessors()
210
- {
211
- $message = new SendGrid\Mail();
212
-
213
- $html = "<p style = 'color:red;'>Sample HTML text</p>";
214
-
215
- $message->setHtml($html);
216
-
217
- $this->assertEquals($html, $message->getHtml());
218
- }
219
-
220
- public function testAttachmentAccessors()
221
- {
222
- $message = new SendGrid\Mail();
223
-
224
- $attachments =
225
- array(
226
- "path/to/file/file_1.txt",
227
- "../file_2.txt",
228
- "../file_3.txt"
229
- );
230
-
231
- $message->setAttachments($attachments);
232
-
233
- $msg_attachments = $message->getAttachments();
234
-
235
- $this->assertEquals(count($attachments), count($msg_attachments));
236
-
237
- for($i = 0; $i < count($attachments); $i++)
238
- {
239
- $this->assertEquals($attachments[$i], $msg_attachments[$i]['file']);
240
- }
241
-
242
- //ensure that addAttachment appends to the list of attachments
243
- $message->addAttachment("../file_4.png");
244
-
245
- $attachments[] = "../file_4.png";
246
-
247
- $msg_attachments = $message->getAttachments();
248
- $this->assertEquals($attachments[count($attachments) - 1], $msg_attachments[count($msg_attachments) - 1]['file']);
249
-
250
-
251
- //Setting an attachment removes all other files
252
- $message->setAttachment("only_attachment.sad");
253
-
254
- $this->assertEquals(1, count($message->getAttachments()));
255
-
256
- //Remove an attachment
257
- $message->removeAttachment("only_attachment.sad");
258
- $this->assertEquals(0, count($message->getAttachments()));
259
- }
260
-
261
- public function testCategoryAccessors()
262
- {
263
- $message = new SendGrid\Mail();
264
-
265
- $message->setCategory('category_0');
266
- $this->assertEquals("{\"category\":[\"category_0\"]}", $message->getHeadersJson());
267
-
268
- $categories = array(
269
- "category_1",
270
- "category_2",
271
- "category_3",
272
- "category_4"
273
- );
274
-
275
- $message->setCategories($categories);
276
-
277
- $header = $message->getHeaders();
278
-
279
- // ensure that the array is the same
280
- $this->assertEquals($categories, $header['category']);
281
-
282
- // uses valid json
283
- $this->assertEquals("{\"category\":[\"category_1\",\"category_2\",\"category_3\",\"category_4\"]}", $message->getHeadersJson());
284
-
285
- // ensure that addCategory appends to the list of categories
286
- $category = "category_5";
287
- $message->addCategory($category);
288
-
289
- $header = $message->getHeaders();
290
-
291
- $this->assertEquals(5, count($header['category']));
292
-
293
- $categories[] = $category;
294
-
295
- $this->assertEquals($categories, $header['category']);
296
-
297
-
298
- // removeCategory removes all occurrences of a category
299
- $message->removeCategory("category_3");
300
-
301
- $header = $message->getHeaders();
302
-
303
- unset($categories[2]);
304
- $categories = array_values($categories);
305
-
306
- $this->assertEquals(4, count($header['category']));
307
-
308
- $this->assertEquals($categories, $header['category']);
309
- }
310
-
311
- public function testSubstitutionAccessors()
312
- {
313
- $message = new SendGrid\Mail();
314
-
315
- $substitutions = array(
316
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
317
- "sub_2" => array("val_2.1", "val_2.2"),
318
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
319
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
320
- );
321
-
322
- $message->setSubstitutions($substitutions);
323
-
324
- $header = $message->getHeaders();
325
-
326
- $this->assertEquals($substitutions, $header['sub']);
327
-
328
- $this->assertEquals("{\"sub\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $message->getHeadersJson());
329
-
330
- // ensure that addSubstitution appends to the list of substitutions
331
-
332
- $sub_vals = array("val_5.1", "val_5.2", "val_5.3", "val_5.4");
333
- $message->addSubstitution("sub_5", $sub_vals);
334
-
335
- $substitutions["sub_5"] = $sub_vals;
336
-
337
- $header = $message->getHeaders();
338
-
339
- $this->assertEquals(5, count($header['sub']));
340
- $this->assertEquals($substitutions, $header['sub']);
341
- }
342
-
343
- public function testSectionAccessors()
344
- {
345
- $message = new SendGrid\Mail();
346
-
347
- $sections = array(
348
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
349
- "sub_2" => array("val_2.1", "val_2.2"),
350
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
351
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
352
- );
353
-
354
- $message->setSections($sections);
355
-
356
- $header = $message->getHeaders();
357
-
358
- $this->assertEquals($sections, $header['section']);
359
-
360
- $this->assertEquals("{\"section\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $message->getHeadersJson());
361
-
362
- // ensure that addSubstitution appends to the list of substitutions
363
-
364
- $section_vals = array("val_5.1", "val_5.2", "val_5.3", "val_5.4");
365
- $message->addSection("sub_5", $section_vals);
366
-
367
- $sections["sub_5"] = $section_vals;
368
-
369
- $header = $message->getHeaders();
370
-
371
- $this->assertEquals(5, count($header['section']));
372
- $this->assertEquals($sections, $header['section']);
373
- }
374
-
375
- public function testUniqueArgumentsAccessors()
376
- {
377
- $message = new SendGrid\Mail();
378
-
379
- $unique_arguments = array(
380
- "sub_1" => array("val_1.1", "val_1.2", "val_1.3"),
381
- "sub_2" => array("val_2.1", "val_2.2"),
382
- "sub_3" => array("val_3.1", "val_3.2", "val_3.3", "val_3.4"),
383
- "sub_4" => array("val_4.1", "val_4.2", "val_4.3")
384
- );
385
-
386
- $message->setUniqueArguments($unique_arguments);
387
-
388
- $header = $message->getHeaders();
389
-
390
- $this->assertEquals($unique_arguments, $header['unique_args']);
391
-
392
- $this->assertEquals("{\"unique_args\":{\"sub_1\":[\"val_1.1\",\"val_1.2\",\"val_1.3\"],\"sub_2\":[\"val_2.1\",\"val_2.2\"],\"sub_3\":[\"val_3.1\",\"val_3.2\",\"val_3.3\",\"val_3.4\"],\"sub_4\":[\"val_4.1\",\"val_4.2\",\"val_4.3\"]}}", $message->getHeadersJson());
393
-
394
- // ensure that addSubstitution appends to the list of substitutions
395
-
396
- $unique_vals = array("val_5.1", "val_5.2", "val_5.3", "val_5.4");
397
- $message->addUniqueArgument("sub_5", $unique_vals);
398
-
399
- $unique_arguments["sub_5"] = $unique_vals;
400
-
401
- $header = $message->getHeaders();
402
-
403
- $this->assertEquals(5, count($header['unique_args']));
404
- $this->assertEquals($unique_arguments, $header['unique_args']);
405
- }
406
-
407
- public function testFilterSettingsAccessors()
408
- {
409
- $message = new SendGrid\Mail();
410
-
411
- $filters =
412
- array(
413
- "filter_1" =>
414
- array(
415
- "settings" =>
416
- array(
417
- "enable" => 1,
418
- "setting_1" => "setting_val_1"
419
- )
420
- ),
421
- "filter_2" =>
422
- array(
423
- "settings" =>
424
- array(
425
- "enable" => 0,
426
- "setting_2" => "setting_val_2",
427
- "setting_3" => "setting_val_3"
428
- )
429
- ),
430
- "filter_3" =>
431
- array(
432
- "settings" =>
433
- array(
434
- "enable" => 0,
435
- "setting_4" => "setting_val_4",
436
- "setting_5" => "setting_val_5"
437
- )
438
- ),
439
- );
440
-
441
- $message->setFilterSettings($filters);
442
-
443
- $header = $message->getHeaders();
444
-
445
- $this->assertEquals(count($filters), count($header['filters']));
446
-
447
- $this->assertEquals($filters, $header['filters']);
448
-
449
-
450
- //the addFilter appends to the filter list
451
- $message->addFilterSetting("filter_4", "enable", 0);
452
- $message->addFilterSetting("filter_4", "setting_6", "setting_val_6");
453
- $message->addFilterSetting("filter_4", "setting_7", "setting_val_7");
454
-
455
- $filters["filter_4"] =
456
- array(
457
- "settings" =>
458
- array(
459
- "enable" => 0,
460
- "setting_6" => "setting_val_6",
461
- "setting_7" => "setting_val_7"
462
- )
463
- );
464
-
465
- $header = $message->getHeaders();
466
-
467
- $this->assertEquals($filters, $header['filters']);
468
- }
469
-
470
- public function testHeaderAccessors()
471
- {
472
- $message = new SendGrid\Mail();
473
-
474
- $this->assertEquals("{}", $message->getHeadersJson());
475
-
476
-
477
- $headers =
478
- array(
479
- "header_1" =>
480
- array(
481
- "item_1" => "value_1",
482
- "item_2" => "value_2",
483
- "item_3" => "value_3"
484
- ),
485
- "header_2" => "value_4",
486
- "header_3" => "value_4",
487
- "header_4" =>
488
- array(
489
- "item_4" =>
490
- array(
491
- "sub_item_1" => "sub_value_1",
492
- "sub_item_2" => "sub_value_2"
493
- )
494
- )
495
- );
496
-
497
-
498
- $message->setHeaders($headers);
499
-
500
-
501
- $this->assertEquals($headers, $message->getHeaders());
502
-
503
- $message->addHeader("simple_header", "simple_value");
504
-
505
- $headers["simple_header"] = "simple_value";
506
-
507
- $this->assertEquals($headers, $message->getHeaders());
508
- $this->assertEquals("{\"header_1\":{\"item_1\":\"value_1\",\"item_2\":\"value_2\",\"item_3\":\"value_3\"},\"header_2\":\"value_4\",\"header_3\":\"value_4\",\"header_4\":{\"item_4\":{\"sub_item_1\":\"sub_value_1\",\"sub_item_2\":\"sub_value_2\"}},\"simple_header\":\"simple_value\"}", $message->getHeadersJson());
509
-
510
- //remove a header
511
- $message->removeHeader("simple_header");
512
-
513
- unset($headers["simple_header"]);
514
-
515
- $this->assertEquals($headers, $message->getHeaders());
516
- }
517
-
518
- public function testUseHeaders()
519
- {
520
- $mail = new SendGrid\Mail();
521
-
522
- $mail->addTo('foo@bar.com')->
523
- addBcc('baa@bar.com')->
524
- setFrom('boo@foo.com')->
525
- setSubject('Subject')->
526
- setHtml('Hello You');
527
-
528
- $this->assertFalse($mail->useHeaders());
529
-
530
- $mail->removeBcc('baa@bar.com');
531
- $this->assertTrue($mail->useHeaders());
532
-
533
- $mail->addCc('bot@bar.com');
534
- $this->assertFalse($mail->useHeaders());
535
-
536
- $mail->removeCc('bot@bar.com')->
537
- setRecipientsinHeader(true);
538
- $this->assertTrue($mail->useHeaders());
539
-
540
- $mail->setRecipientsinHeader(false);
541
- $this->assertFalse($mail->useHeaders());
542
-
543
- $mail->
544
- addBcc('baa@bar.com')->
545
- addAttachment('attachment.ext');
546
-
547
- $this->assertTrue($mail->useHeaders());
548
- }
549
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/SendGrid/SmtpTest.php DELETED
@@ -1,91 +0,0 @@
1
- <?php
2
-
3
- class SmtpTest extends PHPUnit_Framework_TestCase
4
- {
5
- public function testConstruction()
6
- {
7
- $sendgrid = new SendGrid("foo", "bar");
8
-
9
- $smtp = $sendgrid->smtp;
10
-
11
- $this->assertEquals(new SendGrid\Smtp("foo", "bar"), $smtp);
12
-
13
- $message = new SendGrid\Mail();
14
- $message->
15
- setFrom('bar@foo.com')->
16
- setFromName('John Doe')->
17
- setSubject('foobar subject')->
18
- setText('foobar text')->
19
- addTo('foo@bar.com')->
20
- addAttachment("mynewattachment.jpg");
21
-
22
- $this->assertEquals(get_class($smtp), 'SendGrid\Smtp');
23
-
24
- $this->setExpectedException('Swift_TransportException');
25
- $smtp->send($message);
26
- }
27
-
28
- public function testPorts()
29
- {
30
- $this->assertEquals(587, SendGrid\Smtp::TLS);
31
- $this->assertEquals(25, SendGrid\Smtp::TLS_ALTERNATIVE);
32
- $this->assertEquals(465, SendGrid\Smtp::SSL);
33
-
34
- $sendgrid = new SendGrid("foo", "bar");
35
-
36
- //we can't check that the port works, but we can check that it doesn't throw an exception
37
- $object = $sendgrid->smtp->setPort(SendGrid\Smtp::TLS);
38
-
39
- $this->assertEquals($sendgrid->smtp, $object);
40
- $this->assertEquals(get_class($object), 'SendGrid\Smtp');
41
-
42
-
43
- $mock = new SmtpMock('foo', 'bar');
44
-
45
- $mock->setPort('52');
46
- $this->assertEquals('52', $mock->getPort());
47
- }
48
-
49
- public function testEmailBodyAttachments()
50
- {
51
- $_mapToSwift = new ReflectionMethod('SendGrid\Smtp', '_mapToSwift');
52
- $_mapToSwift->setAccessible(true);
53
-
54
- $sendgrid = new SendGrid("foo", "bar");
55
- $message = new SendGrid\Mail();
56
- $message->
57
- setFrom('bar@foo.com')->
58
- setFromName('John Doe')->
59
- setSubject('foobar subject')->
60
- setHtml('foobar html')->
61
- addTo('foo@bar.com');
62
-
63
- $swift_message = $_mapToSwift->invoke($sendgrid->smtp, $message);
64
- $this->assertEquals(count($swift_message->getChildren()), 0);
65
-
66
- $message->setText('foobar text');
67
-
68
- $swift_message = $_mapToSwift->invoke($sendgrid->smtp, $message);
69
- $this->assertEquals(count($swift_message->getChildren()), 1);
70
- $body_attachments = $swift_message->getChildren();
71
- $this->assertEquals($body_attachments[0]->getContentType(), 'text/plain');
72
- }
73
-
74
- public function testEmailTextBodyAttachments()
75
- {
76
- $_mapToSwift = new ReflectionMethod('SendGrid\Smtp', '_mapToSwift');
77
- $_mapToSwift->setAccessible(true);
78
-
79
- $sendgrid = new SendGrid("foo", "bar");
80
- $message = new SendGrid\Mail();
81
- $message->
82
- setFrom('bar@foo.com')->
83
- setFromName('John Doe')->
84
- setSubject('foobar subject')->
85
- setText('foobar text')->
86
- addTo('foo@bar.com');
87
-
88
- $swift_message = $_mapToSwift->invoke($sendgrid->smtp, $message);
89
- $this->assertEquals(count($swift_message->getChildren()), 0);
90
- }
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/SendGrid/WebTest.php DELETED
@@ -1,101 +0,0 @@
1
- <?php
2
-
3
- class WebTest extends PHPUnit_Framework_TestCase
4
- {
5
- public function testConstruction()
6
- {
7
- $sendgrid = new SendGrid("foo", "bar");
8
-
9
- $web = $sendgrid->web;
10
-
11
- $this->assertEquals(new SendGrid\Web("foo", "bar"), $web);
12
- $this->assertEquals(get_class($web), "SendGrid\Web");
13
- }
14
-
15
- public function testMockFunctions()
16
- {
17
- $message = new SendGrid\Mail();
18
-
19
- $message->
20
- setFrom('bar@foo.com')->
21
- setSubject('foobar subject')->
22
- setText('foobar text')->
23
- setHtml('foobar html')->
24
- addTo('foo@bar.com')->
25
- addAttachment("mynewattachment.jpg");
26
-
27
- $mock = new WebMock("foo", "bar");
28
- $data = $mock->testPrepMessageData($message);
29
-
30
- $expected =
31
- array(
32
- 'api_user' => 'foo',
33
- 'api_key' => 'bar',
34
- 'subject' => 'foobar subject',
35
- 'html' => 'foobar html',
36
- 'text' => 'foobar text',
37
- 'from' => 'bar@foo.com',
38
- 'to' => 'bar@foo.com',
39
- 'x-smtpapi' => '{"to":["foo@bar.com"]}',
40
- 'files[mynewattachment.jpg]' => '@mynewattachment.jpg'
41
- );
42
-
43
- $this->assertEquals($expected, $data);
44
-
45
-
46
- $array =
47
- array(
48
- "foo",
49
- "bar",
50
- "car",
51
- "doo"
52
- );
53
-
54
- $url_part = $mock->testArrayToUrlPart($array, "param");
55
-
56
- $this->assertEquals("&param[]=foo&param[]=bar&param[]=car&param[]=doo", $url_part);
57
- }
58
-
59
- public function testOptionalParamters()
60
- {
61
- $message = new SendGrid\Mail();
62
- $mock = new WebMock("foo", "bar");
63
-
64
- // Default Values
65
- $actual_without_optional_params = $mock->testPrepMessageData($message);
66
-
67
- $this->assertArrayNotHasKey('html', $actual_without_optional_params);
68
- $this->assertArrayNotHasKey('text', $actual_without_optional_params);
69
- $this->assertArrayNotHasKey('fromname', $actual_without_optional_params);
70
- $this->assertArrayNotHasKey('replyto', $actual_without_optional_params);
71
-
72
- // Set optional params
73
- $message->setFromName('John Doe');
74
- $message->setReplyTo('swift@sendgrid.com');
75
-
76
- $actual_with_optional_params = $mock->testPrepMessageData($message);
77
-
78
- $this->assertArrayHasKey('fromname', $actual_with_optional_params);
79
- $this->assertEquals('John Doe', $actual_with_optional_params['fromname']);
80
-
81
- $this->assertArrayHasKey('replyto', $actual_with_optional_params);
82
- $this->assertEquals('swift@sendgrid.com', $actual_with_optional_params['replyto']);
83
- }
84
-
85
- public function testSendResponse()
86
- {
87
- $sendgrid = new SendGrid("foo", "bar");
88
-
89
- $message = new SendGrid\Mail();
90
-
91
- $message->
92
- setFrom('bar@foo.com')->
93
- setSubject('foobar subject')->
94
- setText('foobar text')->
95
- addTo('foo@bar.com');
96
-
97
- $response = $sendgrid->web->send($message);
98
-
99
- $this->assertEquals("{\"message\": \"error\", \"errors\": [\"Bad username / password\"]}", $response);
100
- }
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/SendGridTest.php DELETED
@@ -1,36 +0,0 @@
1
- <?php
2
-
3
- class SendGridTest extends PHPUnit_Framework_TestCase
4
- {
5
-
6
- public function testConstruction()
7
- {
8
- $sendgrid = new SendGrid("fake_username", "fake_password");
9
-
10
- $this->assertEquals("SendGrid", get_class($sendgrid));
11
- }
12
-
13
- public function testInitializers()
14
- {
15
- $sendgrid = new SendGrid("fake_username", "fake_password");
16
-
17
- // test the working initializers that we currently have
18
- $smtp = $sendgrid->smtp;
19
- $web = $sendgrid->web;
20
-
21
- $this->assertEquals("SendGrid\Smtp", get_class($smtp));
22
- $this->assertEquals("SendGrid\Web", get_class($web));
23
-
24
- try
25
- {
26
- $sendgrid->notanapi;
27
- }
28
- catch (Exception $e)
29
- {
30
- return;
31
- }
32
-
33
- $this->fail('A non object was instanciated');
34
-
35
- }
36
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/a_loaderTest.php DELETED
@@ -1,7 +0,0 @@
1
- <?php
2
-
3
- //we'll use this class to autoload the appropriate files
4
- require_once __dir__ . "/../vendor/autoload.php";
5
-
6
- //include any mock classes
7
- require_once __dir__ . "/Mock/Mock_loader.php";
 
 
 
 
 
 
 
vendor/sendgrid-php/Test/phpunit.xml DELETED
@@ -1,7 +0,0 @@
1
- <phpunit bootstrap="./a_loaderTest.php">
2
- <testsuites>
3
- <testsuite name="Services SendGrid Test Suite">
4
- <directory>./</directory>
5
- </testsuite>
6
- </testsuites>
7
- </phpunit>
 
 
 
 
 
 
 
vendor/sendgrid-php/composer.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "name": "sendgrid/sendgrid",
3
- "description": "This library allows you to quickly and easily send emails through SendGrid using PHP.",
4
- "version": "1.0.0",
5
- "homepage": "http://sendgrid.com",
6
- "license": "MIT",
7
- "autoload": {
8
- "files": ["SendGrid_loader.php"]
9
- },
10
- "require": {
11
- "swiftmailer/swiftmailer": "v4.3.0"
12
- },
13
- "replace": {
14
- "sendgrid/sendgrid-php": "*"
15
- }
16
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/sendgrid-php/composer.lock CHANGED
@@ -1,70 +1,67 @@
1
  {
2
- "hash": "59c1f81ac7d6ed6c902c71c92db62d84",
 
 
 
 
 
3
  "packages": [
4
  {
5
- "name": "swiftmailer/swiftmailer",
6
- "version": "v4.3.0",
7
  "source": {
8
  "type": "git",
9
- "url": "git://github.com/swiftmailer/swiftmailer.git",
10
- "reference": "v4.3.0"
11
  },
12
  "dist": {
13
  "type": "zip",
14
- "url": "https://github.com/swiftmailer/swiftmailer/archive/v4.3.0.zip",
15
- "reference": "v4.3.0",
16
  "shasum": ""
17
  },
18
  "require": {
19
- "php": ">=5.2.4"
20
  },
21
- "type": "library",
22
- "extra": {
23
- "branch-alias": {
24
- "dev-master": "4.3-dev"
25
- }
26
  },
 
 
 
 
27
  "autoload": {
28
- "files": [
29
- "lib/swift_required.php"
30
- ]
31
  },
32
  "notification-url": "https://packagist.org/downloads/",
33
  "license": [
34
- "LGPL"
35
  ],
36
- "authors": [
37
- {
38
- "name": "Fabien Potencier",
39
- "email": "fabien@symfony.com"
40
- },
41
- {
42
- "name": "Chris Corbyn"
43
- }
44
- ],
45
- "description": "Swiftmailer, free feature-rich PHP mailer",
46
- "homepage": "http://swiftmailer.org",
47
  "keywords": [
48
- "mail",
49
- "mailer"
 
 
 
 
 
 
 
50
  ],
51
- "time": "2013-01-08 15:50:34"
52
  }
53
  ],
54
- "packages-dev": [
55
-
56
- ],
57
- "aliases": [
58
-
59
- ],
60
  "minimum-stability": "stable",
61
- "stability-flags": [
62
-
63
- ],
64
- "platform": [
65
-
66
- ],
67
- "platform-dev": [
68
-
69
- ]
70
  }
1
  {
2
+ "_readme": [
3
+ "This file locks the dependencies of your project to a known state",
4
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
+ "This file is @generated automatically"
6
+ ],
7
+ "hash": "3a90e3b3629e5b3255180ad7f34e52c9",
8
  "packages": [
9
  {
10
+ "name": "sendgrid/smtpapi",
11
+ "version": "0.1.0",
12
  "source": {
13
  "type": "git",
14
+ "url": "https://github.com/sendgrid/smtpapi-php.git",
15
+ "reference": "7d964a32e07732bb2d6d4098c502c712befcd8b5"
16
  },
17
  "dist": {
18
  "type": "zip",
19
+ "url": "https://api.github.com/repos/sendgrid/smtpapi-php/zipball/7d964a32e07732bb2d6d4098c502c712befcd8b5",
20
+ "reference": "7d964a32e07732bb2d6d4098c502c712befcd8b5",
21
  "shasum": ""
22
  },
23
  "require": {
24
+ "php": ">=5.3"
25
  },
26
+ "replace": {
27
+ "sendgrid/smtpapi-php": "*"
 
 
 
28
  },
29
+ "require-dev": {
30
+ "phpunit/phpunit": "3.7.*"
31
+ },
32
+ "type": "library",
33
  "autoload": {
34
+ "psr-0": {
35
+ "Smtpapi": "lib/"
36
+ }
37
  },
38
  "notification-url": "https://packagist.org/downloads/",
39
  "license": [
40
+ "MIT"
41
  ],
42
+ "description": "Build SendGrid X-SMTPAPI headers in PHP.",
43
+ "homepage": "http://github.com/sendgrid/smtpapi-php",
 
 
 
 
 
 
 
 
 
44
  "keywords": [
45
+ "X-SMTP",
46
+ "api",
47
+ "email",
48
+ "grid",
49
+ "send",
50
+ "sendgrid",
51
+ "smtp",
52
+ "smtpapi",
53
+ "xsmtp"
54
  ],
55
+ "time": "2014-12-17 20:38:56"
56
  }
57
  ],
58
+ "packages-dev": null,
59
+ "aliases": [],
 
 
 
 
60
  "minimum-stability": "stable",
61
+ "stability-flags": [],
62
+ "prefer-stable": false,
63
+ "platform": {
64
+ "php": ">=5.3"
65
+ },
66
+ "platform-dev": []
 
 
 
67
  }
vendor/sendgrid-php/lib/SendGrid.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SendGrid {
4
+ const VERSION = '2.2.0';
5
+
6
+ protected $namespace = 'SendGrid',
7
+ $headers = array('Content-Type' => 'application/json'),
8
+ $options,
9
+ $web;
10
+ public $api_user,
11
+ $api_key,
12
+ $url,
13
+ $version = self::VERSION;
14
+
15
+
16
+ public function __construct($api_user, $api_key, $options=array()) {
17
+ $this->api_user = $api_user;
18
+ $this->api_key = $api_key;
19
+
20
+ $options['turn_off_ssl_verification'] = (isset($options['turn_off_ssl_verification']) && $options['turn_off_ssl_verification'] === true);
21
+ $protocol = isset($options['protocol']) ? $options['protocol'] : 'https';
22
+ $host = isset($options['host']) ? $options['host'] : 'api.sendgrid.com';
23
+ $port = isset($options['port']) ? $options['port'] : '';
24
+ $endpoint = isset($options['endpoint']) ? $options['endpoint'] : '/api/mail.send.json';
25
+
26
+ $this->url = isset($options['url']) ? $options['url'] : $protocol . '://' . $host . ($port ? ':' . $port : '') . $endpoint;
27
+
28
+ $this->options = $options;
29
+ }
30
+
31
+ public function send(SendGrid\Email $email) {
32
+ $form = $email->toWebFormat();
33
+ $form['api_user'] = $this->api_user;
34
+ $form['api_key'] = $this->api_key;
35
+
36
+ $response = $this->makeRequest($form);
37
+
38
+ return $response;
39
+ }
40
+
41
+ /**
42
+ * Makes the actual HTTP request to SendGrid
43
+ * @param $form array web ready version of SendGrid\Email
44
+ * @return stdClass parsed JSON returned from SendGrid
45
+ */
46
+ private function makeRequest($form) {
47
+ $ch = curl_init();
48
+
49
+ curl_setopt($ch, CURLOPT_URL, $this->url);
50
+ curl_setopt($ch, CURLOPT_POST, 1);
51
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $form);
52
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
53
+ curl_setopt($ch, CURLOPT_USERAGENT, 'sendgrid/' . $this->version . ';php');
54
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->options['turn_off_ssl_verification']);
55
+
56
+ $response = curl_exec($ch);
57
+
58
+ $error = curl_error($ch);
59
+ if ($error) {
60
+ throw new Exception($error);
61
+ }
62
+
63
+ curl_close($ch);
64
+
65
+ return json_decode($response);
66
+ }
67
+
68
+ public static function register_autoloader() {
69
+ spl_autoload_register(array('SendGrid', 'autoloader'));
70
+ }
71
+
72
+ public static function autoloader($class) {
73
+ // Check that the class starts with 'SendGrid'
74
+ if ($class == 'SendGrid' || stripos($class, 'SendGrid\\') === 0) {
75
+ $file = str_replace('\\', '/', $class);
76
+
77
+ if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
78
+ require_once(dirname(__FILE__) . '/' . $file . '.php');
79
+ }
80
+ }
81
+ }
82
+ }
vendor/sendgrid-php/lib/SendGrid/Email.php ADDED
@@ -0,0 +1,411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace SendGrid;
4
+
5
+ class Email {
6
+
7
+ public $to,
8
+ $from,
9
+ $from_name,
10
+ $reply_to,
11
+ $cc_list,
12
+ $bcc_list,
13
+ $subject,
14
+ $text,
15
+ $html,
16
+ $date,
17
+ $content,
18
+ $headers,
19
+ $smtpapi,
20
+ $attachments;
21
+
22
+ public function __construct() {
23
+ $this->from_name = false;
24
+ $this->reply_to = false;
25
+ $this->smtpapi = new \Smtpapi\Header();
26
+ }
27
+
28
+ /**
29
+ * _removeFromList
30
+ * Given a list of key/value pairs, removes the associated keys
31
+ * where a value matches the given string ($item)
32
+ * @param Array $list - the list of key/value pairs
33
+ * @param String $item - the value to be removed
34
+ */
35
+ private function _removeFromList(&$list, $item, $key_field = null) {
36
+ foreach ($list as $key => $val) {
37
+ if($key_field) {
38
+ if($val[$key_field] == $item) {
39
+ unset($list[$key]);
40
+ }
41
+ } else {
42
+ if ($val == $item) {
43
+ unset($list[$key]);
44
+ }
45
+ }
46
+ }
47
+ //repack the indices
48
+ $list = array_values($list);
49
+ }
50
+
51
+ public function addTo($email, $name=null) {
52
+ $this->smtpapi->addTo($email, $name);
53
+ return $this;
54
+ }
55
+
56
+ public function setTos(array $emails) {
57
+ $this->smtpapi->setTos($emails);
58
+ return $this;
59
+ }
60
+
61
+ public function setFrom($email) {
62
+ $this->from = $email;
63
+ return $this;
64
+ }
65
+
66
+ public function getFrom($as_array = false) {
67
+ if($as_array && ($name = $this->getFromName())) {
68
+ return array("$this->from" => $name);
69
+ } else {
70
+ return $this->from;
71
+ }
72
+ }
73
+
74
+ public function setFromName($name) {
75
+ $this->from_name = $name;
76
+ return $this;
77
+ }
78
+
79
+ public function getFromName() {
80
+ return $this->from_name;
81
+ }
82
+
83
+ public function setReplyTo($email) {
84
+ $this->reply_to = $email;
85
+ return $this;
86
+ }
87
+
88
+ public function getReplyTo() {
89
+ return $this->reply_to;
90
+ }
91
+
92
+ public function setCc($email) {
93
+ $this->cc_list = array($email);
94
+ return $this;
95
+ }
96
+
97
+ public function setCcs(array $email_list) {
98
+ $this->cc_list = $email_list;
99
+ return $this;
100
+ }
101
+
102
+ public function addCc($email) {
103
+ $this->cc_list[] = $email;
104
+ return $this;
105
+ }
106
+
107
+ public function removeCc($email) {
108
+ $this->_removeFromList($this->cc_list, $email);
109
+
110
+ return $this;
111
+ }
112
+
113
+ public function getCcs() {
114
+ return $this->cc_list;
115
+ }
116
+
117
+ public function setBcc($email) {
118
+ $this->bcc_list = array($email);
119
+ return $this;
120
+ }
121
+
122
+ public function setBccs($email_list) {
123
+ $this->bcc_list = $email_list;
124
+ return $this;
125
+ }
126
+
127
+ public function addBcc($email) {
128
+ $this->bcc_list[] = $email;
129
+ return $this;
130
+ }
131
+
132
+ public function removeBcc($email) {
133
+ $this->_removeFromList($this->bcc_list, $email);
134
+ return $this;
135
+ }
136
+
137
+ public function getBccs() {
138
+ return $this->bcc_list;
139
+ }
140
+
141
+ public function setSubject($subject) {
142
+ $this->subject = $subject;
143
+ return $this;
144
+ }
145
+
146
+ public function getSubject() {
147
+ return $this->subject;
148
+ }
149
+
150
+ public function setDate($date) {
151
+ $this->date = $date;
152
+ return $this;
153
+ }
154
+
155
+ public function getDate() {
156
+ return $this->date;
157
+ }
158
+
159
+ public function setText($text) {
160
+ $this->text = $text;
161
+ return $this;
162
+ }
163
+
164
+ public function getText() {
165
+ return $this->text;
166
+ }
167
+
168
+ public function setHtml($html) {
169
+ $this->html = $html;
170
+ return $this;
171
+ }
172
+
173
+ public function getHtml() {
174
+ return $this->html;
175
+ }
176
+
177
+ public function setSendAt($timestamp) {
178
+ $this->smtpapi->setSendAt($timestamp);
179
+ return $this;
180
+ }
181
+
182
+ public function setSendEachAt(array $timestamps) {
183
+ $this->smtpapi->setSendEachAt($timestamps);
184
+ return $this;
185
+ }
186
+
187
+ public function addSendEachAt($timestamp) {
188
+ $this->smtpapi->addSendEachAt($timestamp);
189
+ return $this;
190
+ }
191
+
192
+ public function setAttachments(array $files) {
193
+ $this->attachments = array();
194
+
195
+ foreach($files as $filename => $file) {
196
+ if (is_string($filename)) {
197
+ $this->addAttachment($file, $filename);
198
+ } else {
199
+ $this->addAttachment($file);
200
+ }
201
+ }
202
+
203
+ return $this;
204
+ }
205
+
206
+ public function setAttachment($file, $custom_filename=null, $cid=null) {
207
+ $this->attachments = array($this->_getAttachmentInfo($file, $custom_filename, $cid));
208
+ return $this;
209
+ }
210
+
211
+ public function addAttachment($file, $custom_filename=null, $cid=null) {
212
+ $this->attachments[] = $this->_getAttachmentInfo($file, $custom_filename, $cid);
213
+ return $this;
214
+ }
215
+
216
+ public function getAttachments() {
217
+ return $this->attachments;
218
+ }
219
+
220
+ public function removeAttachment($file) {
221
+ $this->_removeFromList($this->attachments, $file, "file");
222
+ return $this;
223
+ }
224
+
225
+ private function _getAttachmentInfo($file, $custom_filename=null, $cid=null) {
226
+ $info = pathinfo($file);
227
+ $info['file'] = $file;
228
+ if (!is_null($custom_filename)) {
229
+ $info['custom_filename'] = $custom_filename;
230
+ }
231
+ if ($cid !== null) {
232
+ $info['cid'] = $cid;
233
+ }
234
+
235
+ return $info;
236
+ }
237
+
238
+ public function setCategories($categories) {
239
+ $this->smtpapi->setCategories($categories);
240
+ return $this;
241
+ }
242
+
243
+ public function setCategory($category) {
244
+ $this->smtpapi->setCategory($category);
245
+ return $this;
246
+ }
247
+
248
+ public function addCategory($category) {
249
+ $this->smtpapi->addCategory($category);
250
+ return $this;
251
+ }
252
+
253
+ public function removeCategory($category) {
254
+ $this->smtpapi->removeCategory($category);
255
+ return $this;
256
+ }
257
+
258
+ public function setSubstitutions($key_value_pairs) {
259
+ $this->smtpapi->setSubstitutions($key_value_pairs);
260
+ return $this;
261
+ }
262
+
263
+ public function addSubstitution($from_value, array $to_values) {
264
+ $this->smtpapi->addSubstitution($from_value, $to_values);
265
+ return $this;
266
+ }
267
+
268
+ public function setSections(array $key_value_pairs) {
269
+ $this->smtpapi->setSections($key_value_pairs);
270
+ return $this;
271
+ }
272
+
273
+ public function addSection($from_value, $to_value) {
274
+ $this->smtpapi->addSection($from_value, $to_value);
275
+ return $this;
276
+ }
277
+
278
+ public function setUniqueArgs(array $key_value_pairs) {
279
+ $this->smtpapi->setUniqueArgs($key_value_pairs);
280
+ return $this;
281
+ }
282
+
283
+ ## synonym method
284
+ public function setUniqueArguments(array $key_value_pairs) {
285
+ $this->smtpapi->setUniqueArgs($key_value_pairs);
286
+ return $this;
287
+ }
288
+
289
+ public function addUniqueArg($key, $value) {
290
+ $this->smtpapi->addUniqueArg($key, $value);
291
+ return $this;
292
+ }
293
+
294
+ ## synonym method
295
+ public function addUniqueArgument($key, $value) {
296
+ $this->smtpapi->addUniqueArg($key, $value);
297
+ return $this;
298
+ }
299
+
300
+ public function setFilters($filter_settings) {
301
+ $this->smtpapi->setFilters($filter_settings);
302
+ return $this;
303
+ }
304
+
305
+ ## synonym method
306
+ public function setFilterSettings($filter_settings) {
307
+ $this->smtpapi->setFilters($filter_settings);
308
+ return $this;
309
+ }
310
+
311
+ public function addFilter($filter_name, $parameter_name, $parameter_value) {
312
+ $this->smtpapi->addFilter($filter_name, $parameter_name, $parameter_value);
313
+ return $this;
314
+ }
315
+
316
+ ## synonym method
317
+ public function addFilterSetting($filter_name, $parameter_name, $parameter_value) {
318
+ $this->smtpapi->addFilter($filter_name, $parameter_name, $parameter_value);
319
+ return $this;
320
+ }
321
+
322
+ public function getHeaders() {
323
+ return $this->headers;
324
+ }
325
+
326
+ public function getHeadersJson() {
327
+ if (count($this->getHeaders()) <= 0) {
328
+ return "{}";
329
+ }
330
+ return json_encode($this->getHeaders(), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
331
+ }
332
+
333
+ public function setHeaders($key_value_pairs) {
334
+ $this->headers = $key_value_pairs;
335
+ return $this;
336
+ }
337
+
338
+ public function addHeader($key, $value) {
339
+ $this->headers[$key] = $value;
340
+ return $this;
341
+ }
342
+
343
+ public function removeHeader($key) {
344
+ unset($this->headers[$key]);
345
+ return $this;
346
+ }
347
+
348
+ public function toWebFormat() {
349
+ $web = array(
350
+ 'to' => $this->to,
351
+ 'from' => $this->getFrom(),
352
+ 'x-smtpapi' => $this->smtpapi->jsonString(),
353
+ 'subject' => $this->getSubject(),
354
+ 'text' => $this->getText(),
355
+ 'html' => $this->getHtml(),
356
+ 'headers' => $this->getHeadersJson(),
357
+ );
358
+
359
+ if ($this->getCcs()) { $web['cc'] = $this->getCcs(); }
360
+ if ($this->getBccs()) { $web['bcc'] = $this->getBccs(); }
361
+ if ($this->getFromName()) { $web['fromname'] = $this->getFromName(); }
362
+ if ($this->getReplyTo()) { $web['replyto'] = $this->getReplyTo(); }
363
+ if ($this->getDate()) { $web['date'] = $this->getDate(); }
364
+ if ($this->smtpapi->to && (count($this->smtpapi->to) > 0)) { $web['to'] = ""; }
365
+
366
+ $web = $this->updateMissingTo($web);
367
+
368
+ if ($this->getAttachments()) {
369
+ foreach($this->getAttachments() as $f) {
370
+ $file = $f['file'];
371
+ $extension = null;
372
+ if (array_key_exists('extension', $f)) {
373
+ $extension = $f['extension'];
374
+ };
375
+ $filename = $f['filename'];
376
+ $full_filename = $filename;
377
+
378
+ if (isset($extension)) {
379
+ $full_filename = $filename.'.'.$extension;
380
+ }
381
+ if (array_key_exists('custom_filename', $f)) {
382
+ $full_filename = $f['custom_filename'];
383
+ }
384
+
385
+ if (array_key_exists('cid', $f)) {
386
+ $web['content['.$full_filename.']'] = $f['cid'];
387
+ }
388
+
389
+ $contents = '@' . $file;
390
+ if (class_exists('CurlFile', false)) { // php >= 5.5
391
+ $contents = new \CurlFile($file, $extension, $filename);
392
+ }
393
+
394
+ $web['files['.$full_filename.']'] = $contents;
395
+ };
396
+ }
397
+
398
+ return $web;
399
+ }
400
+
401
+ /**
402
+ * There needs to be at least 1 to address, or else the mail won't send.
403
+ * This method modifies the data that will be sent via either Rest
404
+ */
405
+ public function updateMissingTo($data) {
406
+ if ($this->smtpapi->to && (count($this->smtpapi->to) > 0)) {
407
+ $data['to'] = $this->getFrom();
408
+ }
409
+ return $data;
410
+ }
411
+ }
vendor/sendgrid-php/sendgrid-php.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ require 'vendor/autoload.php';
3
+ require 'lib/SendGrid.php';
4
+ ?>
vendor/sendgrid-php/vendor/autoload.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload.php @generated by Composer
4
+
5
+ require_once __DIR__ . '/composer' . '/autoload_real.php';
6
+
7
+ return ComposerAutoloaderInitf00fa89c87d9f3f7ac92a9126860de7f::getLoader();
vendor/sendgrid-php/vendor/composer/ClassLoader.php ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Composer.
5
+ *
6
+ * (c) Nils Adermann <naderman@naderman.de>
7
+ * Jordi Boggiano <j.boggiano@seld.be>
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Composer\Autoload;
14
+
15
+ /**
16
+ * ClassLoader implements a PSR-0 class loader
17
+ *
18
+ * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
19
+ *
20
+ * $loader = new \Composer\Autoload\ClassLoader();
21
+ *
22
+ * // register classes with namespaces
23
+ * $loader->add('Symfony\Component', __DIR__.'/component');
24
+ * $loader->add('Symfony', __DIR__.'/framework');
25
+ *
26
+ * // activate the autoloader
27
+ * $loader->register();
28
+ *
29
+ * // to enable searching the include path (eg. for PEAR packages)
30
+ * $loader->setUseIncludePath(true);
31
+ *
32
+ * In this example, if you try to use a class in the Symfony\Component
33
+ * namespace or one of its children (Symfony\Component\Console for instance),
34
+ * the autoloader will first look for the class under the component/
35
+ * directory, and it will then fallback to the framework/ directory if not
36
+ * found before giving up.
37
+ *
38
+ * This class is loosely based on the Symfony UniversalClassLoader.
39
+ *
40
+ * @author Fabien Potencier <fabien@symfony.com>
41
+ * @author Jordi Boggiano <j.boggiano@seld.be>
42
+ */
43
+ class ClassLoader
44
+ {
45
+ // PSR-4
46
+ private $prefixLengthsPsr4 = array();
47
+ private $prefixDirsPsr4 = array();
48
+ private $fallbackDirsPsr4 = array();
49
+
50
+ // PSR-0
51
+ private $prefixesPsr0 = array();
52
+ private $fallbackDirsPsr0 = array();
53
+
54
+ private $useIncludePath = false;
55
+ private $classMap = array();
56
+
57
+ public function getPrefixes()
58
+ {
59
+ if (!empty($this->prefixesPsr0)) {
60
+ return call_user_func_array('array_merge', $this->prefixesPsr0);
61
+ }
62
+ return array();
63
+ }
64
+
65
+ public function getPrefixesPsr4()
66
+ {
67
+ return $this->prefixDirsPsr4;
68
+ }
69
+
70
+ public function getFallbackDirs()
71
+ {
72
+ return $this->fallbackDirsPsr0;
73
+ }
74
+
75
+ public function getFallbackDirsPsr4()
76
+ {
77
+ return $this->fallbackDirsPsr4;
78
+ }
79
+
80
+ public function getClassMap()
81
+ {
82
+ return $this->classMap;
83
+ }
84
+
85
+ /**
86
+ * @param array $classMap Class to filename map
87
+ */
88
+ public function addClassMap(array $classMap)
89
+ {
90
+ if ($this->classMap) {
91
+ $this->classMap = array_merge($this->classMap, $classMap);
92
+ } else {
93
+ $this->classMap = $classMap;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Registers a set of PSR-0 directories for a given prefix, either
99
+ * appending or prepending to the ones previously set for this prefix.
100
+ *
101
+ * @param string $prefix The prefix
102
+ * @param array|string $paths The PSR-0 root directories
103
+ * @param bool $prepend Whether to prepend the directories
104
+ */
105
+ public function add($prefix, $paths, $prepend = false)
106
+ {
107
+ if (!$prefix) {
108
+ if ($prepend) {
109
+ $this->fallbackDirsPsr0 = array_merge(
110
+ (array) $paths,
111
+ $this->fallbackDirsPsr0
112
+ );
113
+ } else {
114
+ $this->fallbackDirsPsr0 = array_merge(
115
+ $this->fallbackDirsPsr0,
116
+ (array) $paths
117
+ );
118
+ }
119
+
120
+ return;
121
+ }
122
+
123
+ $first = $prefix[0];
124
+ if (!isset($this->prefixesPsr0[$first][$prefix])) {
125
+ $this->prefixesPsr0[$first][$prefix] = (array) $paths;
126
+
127
+ return;
128
+ }
129
+ if ($prepend) {
130
+ $this->prefixesPsr0[$first][$prefix] = array_merge(
131
+ (array) $paths,
132
+ $this->prefixesPsr0[$first][$prefix]
133
+ );
134
+ } else {
135
+ $this->prefixesPsr0[$first][$prefix] = array_merge(
136
+ $this->prefixesPsr0[$first][$prefix],
137
+ (array) $paths
138
+ );
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Registers a set of PSR-4 directories for a given namespace, either
144
+ * appending or prepending to the ones previously set for this namespace.
145
+ *
146
+ * @param string $prefix The prefix/namespace, with trailing '\\'
147
+ * @param array|string $paths The PSR-0 base directories
148
+ * @param bool $prepend Whether to prepend the directories
149
+ *
150
+ * @throws \InvalidArgumentException
151
+ */
152
+ public function addPsr4($prefix, $paths, $prepend = false)
153
+ {
154
+ if (!$prefix) {
155
+ // Register directories for the root namespace.
156
+ if ($prepend) {
157
+ $this->fallbackDirsPsr4 = array_merge(
158
+ (array) $paths,
159
+ $this->fallbackDirsPsr4
160
+ );
161
+ } else {
162
+ $this->fallbackDirsPsr4 = array_merge(
163
+ $this->fallbackDirsPsr4,
164
+ (array) $paths
165
+ );
166
+ }
167
+ } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
168
+ // Register directories for a new namespace.
169
+ $length = strlen($prefix);
170
+ if ('\\' !== $prefix[$length - 1]) {
171
+ throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
172
+ }
173
+ $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
174
+ $this->prefixDirsPsr4[$prefix] = (array) $paths;
175
+ } elseif ($prepend) {
176
+ // Prepend directories for an already registered namespace.
177
+ $this->prefixDirsPsr4[$prefix] = array_merge(
178
+ (array) $paths,
179
+ $this->prefixDirsPsr4[$prefix]
180
+ );
181
+ } else {
182
+ // Append directories for an already registered namespace.
183
+ $this->prefixDirsPsr4[$prefix] = array_merge(
184
+ $this->prefixDirsPsr4[$prefix],
185
+ (array) $paths
186
+ );
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Registers a set of PSR-0 directories for a given prefix,
192
+ * replacing any others previously set for this prefix.
193
+ *
194
+ * @param string $prefix The prefix
195
+ * @param array|string $paths The PSR-0 base directories
196
+ */
197
+ public function set($prefix, $paths)
198
+ {
199
+ if (!$prefix) {
200
+ $this->fallbackDirsPsr0 = (array) $paths;
201
+ } else {
202
+ $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Registers a set of PSR-4 directories for a given namespace,
208
+ * replacing any others previously set for this namespace.
209
+ *
210
+ * @param string $prefix The prefix/namespace, with trailing '\\'
211
+ * @param array|string $paths The PSR-4 base directories
212
+ *
213
+ * @throws \InvalidArgumentException
214
+ */
215
+ public function setPsr4($prefix, $paths)
216
+ {
217
+ if (!$prefix) {
218
+ $this->fallbackDirsPsr4 = (array) $paths;
219
+ } else {
220
+ $length = strlen($prefix);
221
+ if ('\\' !== $prefix[$length - 1]) {
222
+ throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
223
+ }
224
+ $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
225
+ $this->prefixDirsPsr4[$prefix] = (array) $paths;
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Turns on searching the include path for class files.
231
+ *
232
+ * @param bool $useIncludePath
233
+ */
234
+ public function setUseIncludePath($useIncludePath)
235
+ {
236
+ $this->useIncludePath = $useIncludePath;
237
+ }
238
+
239
+ /**
240
+ * Can be used to check if the autoloader uses the include path to check
241
+ * for classes.
242
+ *
243
+ * @return bool
244
+ */
245
+ public function getUseIncludePath()
246
+ {
247
+ return $this->useIncludePath;
248
+ }
249
+
250
+ /**
251
+ * Registers this instance as an autoloader.
252
+ *
253
+ * @param bool $prepend Whether to prepend the autoloader or not
254
+ */
255
+ public function register($prepend = false)
256
+ {
257
+ spl_autoload_register(array($this, 'loadClass'), true, $prepend);
258
+ }
259
+
260
+ /**
261
+ * Unregisters this instance as an autoloader.
262
+ */
263
+ public function unregister()
264
+ {
265
+ spl_autoload_unregister(array($this, 'loadClass'));
266
+ }
267
+
268
+ /**
269
+ * Loads the given class or interface.
270
+ *
271
+ * @param string $class The name of the class
272
+ * @return bool|null True if loaded, null otherwise
273
+ */
274
+ public function loadClass($class)
275
+ {
276
+ if ($file = $this->findFile($class)) {
277
+ includeFile($file);
278
+
279
+ return true;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Finds the path to the file where the class is defined.
285
+ *
286
+ * @param string $class The name of the class
287
+ *
288
+ * @return string|false The path if found, false otherwise
289
+ */
290
+ public function findFile($class)
291
+ {
292
+ // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
293
+ if ('\\' == $class[0]) {
294
+ $class = substr($class, 1);
295
+ }
296
+
297
+ // class map lookup
298
+ if (isset($this->classMap[$class])) {
299
+ return $this->classMap[$class];
300
+ }
301
+
302
+ $file = $this->findFileWithExtension($class, '.php');
303
+
304
+ // Search for Hack files if we are running on HHVM
305
+ if ($file === null && defined('HHVM_VERSION')) {
306
+ $file = $this->findFileWithExtension($class, '.hh');
307
+ }
308
+
309
+ if ($file === null) {
310
+ // Remember that this class does not exist.
311
+ return $this->classMap[$class] = false;
312
+ }
313
+
314
+ return $file;
315
+ }
316
+
317
+ private function findFileWithExtension($class, $ext)
318
+ {
319
+ // PSR-4 lookup
320
+ $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
321
+
322
+ $first = $class[0];
323
+ if (isset($this->prefixLengthsPsr4[$first])) {
324
+ foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
325
+ if (0 === strpos($class, $prefix)) {
326
+ foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
327
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
328
+ return $file;
329
+ }
330
+ }
331
+ }
332
+ }
333
+ }
334
+
335
+ // PSR-4 fallback dirs
336
+ foreach ($this->fallbackDirsPsr4 as $dir) {
337
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
338
+ return $file;
339
+ }
340
+ }
341
+
342
+ // PSR-0 lookup
343
+ if (false !== $pos = strrpos($class, '\\')) {
344
+ // namespaced class name
345
+ $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
346
+ . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
347
+ } else {
348
+ // PEAR-like class name
349
+ $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
350
+ }
351
+
352
+ if (isset($this->prefixesPsr0[$first])) {
353
+ foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
354
+ if (0 === strpos($class, $prefix)) {
355
+ foreach ($dirs as $dir) {
356
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
357
+ return $file;
358
+ }
359
+ }
360
+ }
361
+ }
362
+ }
363
+
364
+ // PSR-0 fallback dirs
365
+ foreach ($this->fallbackDirsPsr0 as $dir) {
366
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
367
+ return $file;
368
+ }
369
+ }
370
+
371
+ // PSR-0 include paths.
372
+ if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
373
+ return $file;
374
+ }
375
+ }
376
+ }
377
+
378
+ /**
379
+ * Scope isolated include.
380
+ *
381
+ * Prevents access to $this/self from included files.
382
+ */
383
+ function includeFile($file)
384
+ {
385
+ include $file;
386
+ }
vendor/sendgrid-php/vendor/composer/autoload_classmap.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_classmap.php @generated by Composer
4
+
5
+ $vendorDir = dirname(dirname(__FILE__));
6
+ $baseDir = dirname($vendorDir);
7
+
8
+ return array(
9
+ );
vendor/sendgrid-php/vendor/composer/autoload_namespaces.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_namespaces.php @generated by Composer
4
+
5
+ $vendorDir = dirname(dirname(__FILE__));
6
+ $baseDir = dirname($vendorDir);
7
+
8
+ return array(
9
+ 'Smtpapi' => array($vendorDir . '/sendgrid/smtpapi/lib'),
10
+ 'SendGrid' => array($baseDir . '/lib'),
11
+ );
vendor/sendgrid-php/vendor/composer/autoload_psr4.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_psr4.php @generated by Composer
4
+
5
+ $vendorDir = dirname(dirname(__FILE__));
6
+ $baseDir = dirname($vendorDir);
7
+
8
+ return array(
9
+ );
vendor/sendgrid-php/vendor/composer/autoload_real.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_real.php @generated by Composer
4
+
5
+ class ComposerAutoloaderInitf00fa89c87d9f3f7ac92a9126860de7f
6
+ {
7
+ private static $loader;
8
+
9
+ public static function loadClassLoader($class)
10
+ {
11
+ if ('Composer\Autoload\ClassLoader' === $class) {
12
+ require __DIR__ . '/ClassLoader.php';
13
+ }
14
+ }
15
+
16
+ public static function getLoader()
17
+ {
18
+ if (null !== self::$loader) {
19
+ return self::$loader;
20
+ }
21
+
22
+ spl_autoload_register(array('ComposerAutoloaderInitf00fa89c87d9f3f7ac92a9126860de7f', 'loadClassLoader'), true, true);
23
+ self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitf00fa89c87d9f3f7ac92a9126860de7f', 'loadClassLoader'));
25
+
26
+ $map = require __DIR__ . '/autoload_namespaces.php';
27
+ foreach ($map as $namespace => $path) {
28
+ $loader->set($namespace, $path);
29
+ }
30
+
31
+ $map = require __DIR__ . '/autoload_psr4.php';
32
+ foreach ($map as $namespace => $path) {
33
+ $loader->setPsr4($namespace, $path);
34
+ }
35
+
36
+ $classMap = require __DIR__ . '/autoload_classmap.php';
37
+ if ($classMap) {
38
+ $loader->addClassMap($classMap);
39
+ }
40
+
41
+ $loader->register(true);
42
+
43
+ return $loader;
44
+ }
45
+ }
46
+
47
+ function composerRequiref00fa89c87d9f3f7ac92a9126860de7f($file)
48
+ {
49
+ require $file;
50
+ }
vendor/sendgrid-php/vendor/composer/installed.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "sendgrid/smtpapi",
4
+ "version": "0.1.0",
5
+ "version_normalized": "0.1.0.0",
6
+ "source": {
7
+ "type": "git",
8
+ "url": "https://github.com/sendgrid/smtpapi-php.git",
9
+ "reference": "7d964a32e07732bb2d6d4098c502c712befcd8b5"
10
+ },
11
+ "dist": {
12
+ "type": "zip",
13
+ "url": "https://api.github.com/repos/sendgrid/smtpapi-php/zipball/7d964a32e07732bb2d6d4098c502c712befcd8b5",
14
+ "reference": "7d964a32e07732bb2d6d4098c502c712befcd8b5",
15
+ "shasum": ""
16
+ },
17
+ "require": {
18
+ "php": ">=5.3"
19
+ },
20
+ "replace": {
21
+ "sendgrid/smtpapi-php": "*"
22
+ },
23
+ "require-dev": {
24
+ "phpunit/phpunit": "3.7.*"
25
+ },
26
+ "time": "2014-12-17 20:38:56",
27
+ "type": "library",
28
+ "installation-source": "dist",
29
+ "autoload": {
30
+ "psr-0": {
31
+ "Smtpapi": "lib/"
32
+ }
33
+ },
34
+ "notification-url": "https://packagist.org/downloads/",
35
+ "license": [
36
+ "MIT"
37
+ ],
38
+ "description": "Build SendGrid X-SMTPAPI headers in PHP.",
39
+ "homepage": "http://github.com/sendgrid/smtpapi-php",
40
+ "keywords": [
41
+ "X-SMTP",
42
+ "api",
43
+ "email",
44
+ "grid",
45
+ "send",
46
+ "sendgrid",
47
+ "smtp",
48
+ "smtpapi",
49
+ "xsmtp"
50
+ ]
51
+ }
52
+ ]
vendor/sendgrid-php/vendor/sendgrid/smtpapi/README.md ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # smtpapi-php
2
+
3
+ This php library allows you to quickly and more easily generate SendGrid X-SMTPAPI headers.
4
+
5
+ [![BuildStatus](https://api.travis-ci.org/sendgrid/smtpapi-php.png?branch=master)](https://travis-ci.org/sendgrid/smtpapi-php)
6
+ [![Latest Stable Version](https://poser.pugx.org/sendgrid/smtpapi/version.png)](https://packagist.org/packages/sendgrid/smtpapi)
7
+
8
+ ## Installation
9
+
10
+ The following recommended installation requires [http://getcomposer.org](composer).
11
+
12
+ Add the following to your `composer.json` file.
13
+
14
+ ```json
15
+ {
16
+ "minimum-stability" : "dev",
17
+ "require": {
18
+ "sendgrid/smtpapi": "0.0.2"
19
+ }
20
+ }
21
+ ```
22
+
23
+ Then at the top of your script require the autoloader:
24
+
25
+ ```bash
26
+ require 'vendor/autoload.php';
27
+ ```
28
+
29
+ #### Alternative: Install from zip
30
+
31
+ If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://sendgrid-open-source.s3.amazonaws.com/smtpapi-php/smtpapi-php.zip)**.
32
+
33
+ Then require the library from package:
34
+
35
+ ```php
36
+ require("path/to/smtpapi-php/smtpapi-php.php");
37
+ ```
38
+
39
+ Previous versions of the library can be found in the [version index](https://sendgrid-open-source.s3.amazonaws.com/index.html).
40
+
41
+ ## Usage
42
+
43
+ ### Initializing
44
+
45
+ ```php
46
+ $header = new Smtpapi\Header();
47
+ ```
48
+
49
+ ### jsonString
50
+
51
+ This gives you back the stringified json formatted X-SMTPAPI header. Use this with your [smtp client](https://github.com/andris9/simplesmtp) of choice.
52
+
53
+ ```php
54
+ $header = new Smtpapi\Header();
55
+ $header->jsonString();
56
+ ```
57
+
58
+ If you don't want to unicode escape, you can set options parameter for jsonString() (PHP 5.4 or later).
59
+
60
+ ```php
61
+ $header = new Smtpapi\Header();
62
+ $header->jsonString(JSON_UNESCAPED_UNICODE);
63
+ ```
64
+
65
+ ### addTo
66
+
67
+ ```php
68
+ $header = new Smtpapi\Header();
69
+ $header->addTo('you@youremail.com');
70
+ $header->addTo('other@otheremail.com');
71
+ ```
72
+
73
+ ### setTos
74
+
75
+ ```php
76
+ $header = new Smtpapi\Header();
77
+ $header->setTos(array('you@youremail.com', 'other@otheremail.com'));
78
+ ```
79
+
80
+ ### setSendAt
81
+
82
+ ```php
83
+ $header = new Smtpapi\Header();
84
+ $header->setSendAt(1409348513);
85
+ ```
86
+
87
+ ### setSendEachAt
88
+
89
+ ```php
90
+ $header = new Smtpapi\Header();
91
+ $header->setSendEachAt(array(1409348513, 1409348514, 1409348515));
92
+ ```
93
+
94
+ ### addSendEachAt
95
+
96
+ ```php
97
+ $header = new Smtpapi\Header();
98
+ $header->addSendEachAt(1409348513);
99
+ $header->addSendEachAt(1409348514);
100
+ $header->addSendEachAt(1409348515);
101
+ ```
102
+
103
+ ### addSubstitution
104
+
105
+ ```php
106
+ $header = new Smtpapi\Header();
107
+ $header->addSubstitution('keep', array('secret')); // sub = {keep: ['secret']}
108
+ $header->addSubstitution('other', array('one', 'two')); // sub = {keep: ['secret'], other: ['one', 'two']}
109
+ ```
110
+
111
+ ### setSubstitutions
112
+
113
+ ```php
114
+ $header = new Smtpapi\Header();
115
+ $header->setSubstitutions(array('keep' => array('secret'))); // sub = {keep: ['secret']}
116
+ ```
117
+ ### addUniqueArg
118
+
119
+ ```php
120
+ $header = new Smtpapi\Header();
121
+ $header->addUniqueArg('cat', 'dogs');
122
+ ```
123
+
124
+ ### setUniqueArgs
125
+
126
+ ```php
127
+ $header = new Smtpapi\Header();
128
+ $header->setUniqueArgs(array('cow' => 'chicken'));
129
+ $header->setUniqueArgs(array('dad' => 'proud'));
130
+ ```
131
+
132
+ ### addCategory
133
+
134
+ ```php
135
+ $header = new Smtpapi\Header();
136
+ $header->addCategory('tactics'); // category = ['tactics']
137
+ $header->addCategory('advanced'); // category = ['tactics', 'advanced']
138
+ ```
139
+
140
+ ### setCategories
141
+
142
+ ```php
143
+ $header = new Smtpapi\Header();
144
+ $header->setCategories(array('tactics', 'advanced')); // category = ['tactics', 'advanced']
145
+ ```
146
+
147
+ ### addSection
148
+
149
+ ```php
150
+ $header = new Smtpapi\Header();
151
+ $header->addSection('-charge-': 'This ship is useless.');
152
+ $header->addSection('-bomber-', 'Only for sad vikings.');
153
+ ```
154
+
155
+ ### setSections
156
+
157
+ ```php
158
+ $header = new Smtpapi\Header();
159
+ $header->setSections(array('-charge-' => 'This ship is useless.'));
160
+ ```
161
+
162
+ ### addFilter
163
+
164
+ ```php
165
+ $header = new Smtpapi\Header();
166
+ $header->addFilter('footer', 'enable', 1);
167
+ $header->addFilter('footer', 'text/html', '<strong>boo</strong>');
168
+ ```
169
+
170
+ ### setFilters
171
+
172
+ ```php
173
+ $header = new Smtpapi\Header();
174
+ $filter = array(
175
+ 'footer' => array(
176
+ 'setting' => array(
177
+ 'enable' => 1,
178
+ "text/plain" => 'You can haz footers!'
179
+ )
180
+ )
181
+ );
182
+ $header->setFilters($filter);
183
+ ```
184
+
185
+ ## SendGrid SMTP Example
186
+
187
+ The following example builds the X-SMTPAPI headers and adds them to swiftmailer. [Swiftmailer](http://swiftmailer.org/) then sends the email through SendGrid. You can use this same code in your application or optionally you can use [sendgrid-php](http://github.com/sendgrid/sendgrid-php).
188
+
189
+ ```php
190
+ $transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
191
+ $transport->setUsername("sendgrid_username");
192
+ $transport->setPassword("sendgrid_password");
193
+
194
+ $mailer = Swift_Mailer::newInstance($transport);
195
+
196
+ $message = new Swift_Message();
197
+ $message->setTos(array("bar@blurdybloop.com"));
198
+ $message->setFrom("foo@blurdybloop.com");
199
+ $message->setSubject("Hello");
200
+ $message->setBody("%how% are you doing?");
201
+
202
+ $header = new Smtpapi\Header();
203
+ $header->addSubstitution("%how%", array("Owl"));
204
+
205
+ $message_headers = $message->getHeaders();
206
+ $message_headers->addTextHeader("x-smtpapi", $header->jsonString());
207
+
208
+ try {
209
+ $response = $mailer->send($message);
210
+ print_r($response);
211
+ } catch(\Swift_TransportException $e) {
212
+ print_r('Bad username / password');
213
+ }
214
+ ```
215
+
216
+ ## Contributing
217
+
218
+ 1. Fork it
219
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
220
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
221
+ 4. Push to the branch (`git push origin my-new-feature`)
222
+ 5. Create new Pull Request
223
+
224
+ ## Running Tests
225
+
226
+ The existing tests in the `test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:
227
+
228
+ ````bash
229
+ composer update --dev
230
+ cd test
231
+ ../vendor/bin/phpunit
232
+ ```
233
+
234
+ or if you already have PHPUnit installed globally.
235
+
236
+ ```bash
237
+ cd test
238
+ phpunit
239
+ ```
240
+
241
+ #### Testing uploading to Amazon S3
242
+
243
+ If you want to test uploading the zipped file to Amazon S3 (SendGrid employees only), do the following.
244
+
245
+ ```
246
+ export S3_SIGNATURE="secret_signature"
247
+ export S3_POLICY="secret_policy"
248
+ export S3_BUCKET="sendgrid-open-source"
249
+ export S3_ACCESS_KEY="secret_access_key"
250
+ ./scripts/s3upload.sh
251
+ ```
vendor/sendgrid-php/vendor/sendgrid/smtpapi/lib/Smtpapi.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smtpapi {
4
+ const VERSION = "0.1.0";
5
+
6
+ public static function register_autoloader() {
7
+ spl_autoload_register(array('Smtpapi', 'autoloader'));
8
+ }
9
+
10
+ public static function autoloader($class) {
11
+ // Check that the class starts with "Smtpapi"
12
+ if ($class == 'Smtpapi' || stripos($class, 'Smtpapi\\') === 0) {
13
+ $file = str_replace('\\', '/', $class);
14
+
15
+ if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
16
+ require_once(dirname(__FILE__) . '/' . $file . '.php');
17
+ }
18
+ }
19
+ }
20
+ }
vendor/sendgrid-php/vendor/sendgrid/smtpapi/lib/Smtpapi/Header.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Smtpapi;
4
+
5
+ class Header {
6
+ public $to = array();
7
+ public $sub = array();
8
+ public $unique_args = array();
9
+ public $category = array();
10
+ public $section = array();
11
+ public $filters = array();
12
+ public $send_at = null;
13
+ public $send_each_at = array();
14
+
15
+ public function __construct() {}
16
+
17
+ public function addTo($email, $name=null) {
18
+ $this->to[] = ($name ? $name . " <" . $email . ">" : $email);
19
+ return $this;
20
+ }
21
+
22
+ public function setTos(array $emails) {
23
+ $this->to = $emails;
24
+ return $this;
25
+ }
26
+
27
+ public function setSendAt($send_at) {
28
+ $this->send_at = $send_at;
29
+ $this->send_each_at = array();
30
+ return $this;
31
+ }
32
+
33
+ public function setSendEachAt(array $send_each_at) {
34
+ $this->send_each_at = $send_each_at;
35
+ $this->send_at = null;
36
+ return $this;
37
+ }
38
+
39
+ public function addSendEachAt($send_at) {
40
+ $this->send_at = null;
41
+ $this->send_each_at[] = $send_at;
42
+ return $this;
43
+ }
44
+
45
+ public function addSubstitution($from_value, array $to_values) {
46
+ $this->sub[$from_value] = $to_values;
47
+ return $this;
48
+ }
49
+
50
+ public function setSubstitutions($key_value_pairs) {
51
+ $this->sub = $key_value_pairs;
52
+ return $this;
53
+ }
54
+
55
+ public function addUniqueArg($key, $value) {
56
+ $this->unique_args[$key] = $value;
57
+ return $this;
58
+ }
59
+
60
+ public function setUniqueArgs(array $key_value_pairs) {
61
+ $this->unique_args = $key_value_pairs;
62
+ return $this;
63
+ }
64
+
65
+ public function addCategory($category) {
66
+ $this->category[] = $category;
67
+ return $this;
68
+ }
69
+
70
+ public function setCategories($categories) {
71
+ $this->category = $categories;
72
+ return $this;
73
+ }
74
+
75
+ public function addSection($from_value, $to_value) {
76
+ $this->section[$from_value] = $to_value;
77
+ return $this;
78
+ }
79
+
80
+ public function setSections(array $key_value_pairs) {
81
+ $this->section = $key_value_pairs;
82
+ return $this;
83
+ }
84
+
85
+ public function addFilter($filter_name, $parameter_name, $parameter_value) {
86
+ $this->filters[$filter_name]['settings'][$parameter_name] = $parameter_value;
87
+ return $this;
88
+ }
89
+
90
+ public function setFilters($filter_setting) {
91
+ $this->filters = $filter_setting;
92
+ return $this;
93
+ }
94
+
95
+ private function toArray() {
96
+ $data = array();
97
+
98
+ if ($this->to) {
99
+ $data["to"] = $this->to;
100
+ }
101
+ if ($this->sub) {
102
+ $data["sub"] = $this->sub;
103
+ }
104
+ if ($this->unique_args) {
105
+ $data["unique_args"] = $this->unique_args;
106
+ }
107
+ if ($this->category) {
108
+ $data["category"] = $this->category;
109
+ }
110
+ if ($this->section) {
111
+ $data["section"] = $this->section;
112
+ }
113
+ if ($this->filters) {
114
+ $data["filters"] = $this->filters;
115
+ }
116
+ if ($this->send_at) {
117
+ $data["send_at"] = $this->send_at;
118
+ }
119
+ if ($this->send_each_at) {
120
+ $data["send_each_at"] = $this->send_each_at;
121
+ }
122
+
123
+ return $data;
124
+ }
125
+
126
+ public function jsonString($options = null) {
127
+ if ($options == null) {
128
+ $options = JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP;
129
+ }
130
+ if (count($this->toArray()) <= 0) {
131
+ return "{}";
132
+ }
133
+
134
+ $json_string = json_encode($this->toArray(), $options);
135
+
136
+ // unescape 5.3 PHP's escaping of forward slashes
137
+ return str_replace('\\/', '/', $json_string);
138
+ }
139
+ }
view/js/sendgrid.stats.js CHANGED
@@ -109,6 +109,9 @@ jQuery(document).ready(function($) {
109
 
110
  /* Get stats from request */
111
  response = jQuery.parseJSON(response);
 
 
 
112
  jQuery.each(response, function(key, value) {
113
  var dateString = _splitDate(value.date);
114
  var date = Date.UTC(dateString[0], _convertMonthToUTC(dateString[1]), dateString[2]);
109
 
110
  /* Get stats from request */
111
  response = jQuery.parseJSON(response);
112
+ if (undefined != response.error) {
113
+ response = [];
114
+ }
115
  jQuery.each(response, function(key, value) {
116
  var dateString = _splitDate(value.date);
117
  var date = Date.UTC(dateString[0], _convertMonthToUTC(dateString[1]), dateString[2]);
view/sendgrid_contextual_help.php CHANGED
@@ -79,4 +79,24 @@
79
  remove_filter('wp_mail_content_type', 'set_html_content_type');
80
  </span>
81
  to remove the 'text/html' filter to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  </p>
79
  remove_filter('wp_mail_content_type', 'set_html_content_type');
80
  </span>
81
  to remove the 'text/html' filter to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
82
+ <p><b>Define SendGrid settings as global variables (wp-config.php):</b></p>
83
+ <p>
84
+ <ol>
85
+ <li>Set credentials (both need to be set in order to get credentials from variables and not from the database):
86
+ <ul>
87
+ <li>Username: <span class="code">define('SENDGRID_USERNAME', 'sendgrid_username');</span></li>
88
+ <li>Password: <span class="code">define('SENDGRID_PASSWORD', 'sendgrid_password');</span></li>
89
+ </ul>
90
+ </li>
91
+ <li>Set email related settings:
92
+ <ul>
93
+ <li>Send method ('api' or 'smtp'): <span class="code">define('SENDGRID_SEND_METHOD', 'api');</span></li>
94
+ <li>From name: <span class="code">define('SENDGRID_FROM_NAME', 'Example Name');</span></li>
95
+ <li>From email: <span class="code">define('SENDGRID_FROM_EMAIL', 'from_email@example.com');</span></li>
96
+ <li>Reply to email: <span class="code">define('SENDGRID_REPLY_TO', 'reply_to@example.com');</span></li>
97
+ <li>Categories: <span class="code">define('SENDGRID_CATEGORIES', 'category_1,category_2');</span></li>
98
+ </ul>
99
+ </li>
100
+ </ol>
101
+ </p>
102
  </p>
view/sendgrid_settings.php CHANGED
@@ -17,19 +17,28 @@
17
  <tr valign="top">
18
  <th scope="row"><?php _e("Username: "); ?></th>
19
  <td>
20
- <input type="text" required="true" name="sendgrid_user" value="<?php echo $user; ?>" size="20" class="regular-text">
21
  </td>
22
  </tr>
23
  <tr valign="top">
24
  <th scope="row"><?php _e("Password: "); ?></th>
25
  <td>
26
- <input type="password" required="true" name="sendgrid_pwd" value="<?php echo $password; ?>" size="20" class="regular-text">
27
  </td>
28
  </tr>
 
 
 
 
 
 
 
 
 
29
  <tr valign="top">
30
  <th scope="row"><?php _e("Send Mail with: "); ?></th>
31
  <td>
32
- <select name="sendgrid_api">
33
  <option value="api" id="api" <?php echo ( 'api' == $method ) ? 'selected' : '' ?>><?php _e('API') ?></option>
34
  <option value="smtp" id="smtp" <?php echo ( 'smtp' == $method ) ? 'selected' : '' ?>><?php _e('SMTP') ?></option>
35
  </select>
@@ -44,21 +53,21 @@
44
  <tr valign="top">
45
  <th scope="row"><?php _e("Name: "); ?></th>
46
  <td>
47
- <input type="text" name="sendgrid_name" value="<?php echo $name; ?>" size="20" class="regular-text">
48
  <p class="description"><?php _e('Name as it will appear in recipient clients.') ?></p>
49
  </td>
50
  </tr>
51
  <tr valign="top">
52
  <th scope="row"><?php _e("Sending Address: "); ?></th>
53
  <td>
54
- <input type="email" name="sendgrid_email" value="<?php echo $email; ?>" size="20" class="regular-text">
55
  <p class="description"><?php _e('Email address from which the message will be sent,') ?></p>
56
  </td>
57
  </tr>
58
  <tr valign="top">
59
  <th scope="row"><?php _e("Reply Address: "); ?></th>
60
  <td>
61
- <input type="email" name="sendgrid_reply_to" value="<?php echo $reply_to; ?>" size="20" class="regular-text">
62
  <span><small><em><?php _e('Leave blank to use Sending Address.') ?></em></small></span>
63
  <p class="description"><?php _e('Email address where replies will be returned.') ?></p>
64
  </td>
@@ -66,12 +75,19 @@
66
  <tr valign="top">
67
  <th scope="row"><?php _e("Categories: "); ?></th>
68
  <td>
69
- <input type="text" name="sendgrid_categories" value="<?php echo $categories; ?>" size="20" class="regular-text">
70
  <span><small><em><?php _e('Leave blank to send without categories.') ?></em></small></span>
71
  <p class="description"><?php _e('Associates the category of the email this should be logged as. <br />
72
  Categories must be separated by commas (Example: category1, category2).') ?></p>
73
  </td>
74
  </tr>
 
 
 
 
 
 
 
75
  </tbody>
76
  </table>
77
  <p class="submit">
@@ -79,7 +95,7 @@
79
  </p>
80
  </form>
81
  <br />
82
- <?php if ( $valid_credentials ): ?>
83
  <h2><?php _e('SendGrid Test') ?></h2>
84
  <h3><?php _e('Send a test email with these settings') ?></h3>
85
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
17
  <tr valign="top">
18
  <th scope="row"><?php _e("Username: "); ?></th>
19
  <td>
20
+ <input type="text" required="true" name="sendgrid_user" value="<?php echo $user; ?>" size="20" class="regular-text" <?php disabled( $are_global_credentials ); ?>>
21
  </td>
22
  </tr>
23
  <tr valign="top">
24
  <th scope="row"><?php _e("Password: "); ?></th>
25
  <td>
26
+ <input type="password" required="true" name="sendgrid_pwd" value="<?php echo ( $are_global_credentials ? "******" : $password ); ?>" size="20" class="regular-text" <?php disabled( $are_global_credentials ); ?>>
27
  </td>
28
  </tr>
29
+ <?php if ( $are_global_credentials ): ?>
30
+ <tr valign="top">
31
+ <td colspan="2">
32
+ <p>
33
+ <?php _e('Your credentials are already configured in the config file. You can not, also, specify them in the interface.'); ?>
34
+ </p>
35
+ </td>
36
+ </tr>
37
+ <?php endif; ?>
38
  <tr valign="top">
39
  <th scope="row"><?php _e("Send Mail with: "); ?></th>
40
  <td>
41
+ <select name="sendgrid_api" <?php disabled( defined('SENDGRID_SEND_METHOD') ); ?>>
42
  <option value="api" id="api" <?php echo ( 'api' == $method ) ? 'selected' : '' ?>><?php _e('API') ?></option>
43
  <option value="smtp" id="smtp" <?php echo ( 'smtp' == $method ) ? 'selected' : '' ?>><?php _e('SMTP') ?></option>
44
  </select>
53
  <tr valign="top">
54
  <th scope="row"><?php _e("Name: "); ?></th>
55
  <td>
56
+ <input type="text" name="sendgrid_name" value="<?php echo $name; ?>" size="20" class="regular-text" <?php disabled( defined('SENDGRID_FROM_NAME') ); ?>>
57
  <p class="description"><?php _e('Name as it will appear in recipient clients.') ?></p>
58
  </td>
59
  </tr>
60
  <tr valign="top">
61
  <th scope="row"><?php _e("Sending Address: "); ?></th>
62
  <td>
63
+ <input type="email" name="sendgrid_email" value="<?php echo $email; ?>" size="20" class="regular-text" <?php disabled( defined('SENDGRID_FROM_EMAIL') ); ?>>
64
  <p class="description"><?php _e('Email address from which the message will be sent,') ?></p>
65
  </td>
66
  </tr>
67
  <tr valign="top">
68
  <th scope="row"><?php _e("Reply Address: "); ?></th>
69
  <td>
70
+ <input type="email" name="sendgrid_reply_to" value="<?php echo $reply_to; ?>" size="20" class="regular-text" <?php disabled( defined('SENDGRID_REPLY_TO') ); ?>>
71
  <span><small><em><?php _e('Leave blank to use Sending Address.') ?></em></small></span>
72
  <p class="description"><?php _e('Email address where replies will be returned.') ?></p>
73
  </td>
75
  <tr valign="top">
76
  <th scope="row"><?php _e("Categories: "); ?></th>
77
  <td>
78
+ <input type="text" name="sendgrid_categories" value="<?php echo $categories; ?>" size="20" class="regular-text" <?php disabled( defined('SENDGRID_CATEGORIES') ); ?>>
79
  <span><small><em><?php _e('Leave blank to send without categories.') ?></em></small></span>
80
  <p class="description"><?php _e('Associates the category of the email this should be logged as. <br />
81
  Categories must be separated by commas (Example: category1, category2).') ?></p>
82
  </td>
83
  </tr>
84
+ <tr valign="top">
85
+ <td colspan="2">
86
+ <p>
87
+ <?php _e('Disabled fields in this form means that they are already configured in the config file.'); ?>
88
+ </p>
89
+ </td>
90
+ </tr>
91
  </tbody>
92
  </table>
93
  <p class="submit">
95
  </p>
96
  </form>
97
  <br />
98
+ <?php if ( !isset($status) or 'updated' == $status ): ?>
99
  <h2><?php _e('SendGrid Test') ?></h2>
100
  <h3><?php _e('Send a test email with these settings') ?></h3>
101
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
view/sendgrid_stats.php CHANGED
@@ -6,8 +6,16 @@
6
  </div>
7
  <div class="pull-right sendgrid-statistics-change-type">
8
  <select id="sendgrid-statistics-change-type">
9
- <option value="wordpress" selected="selected">Wordpress statistics</option>
10
  <option value="general">General statistics</option>
 
 
 
 
 
 
 
 
 
11
  </select>
12
  </div>
13
 
6
  </div>
7
  <div class="pull-right sendgrid-statistics-change-type">
8
  <select id="sendgrid-statistics-change-type">
 
9
  <option value="general">General statistics</option>
10
+ <option value="wordpress" selected="selected">Wordpress statistics</option>
11
+ <?php $categories = Sendgrid_Tools::get_categories_array(); ?>
12
+ <?php if ( is_array( $categories ) and count( $categories ) > 0 ): ?>
13
+ <optgroup label="Categories:">
14
+ <?php foreach ( $categories as $cateogry ): ?>
15
+ <option value="<?php echo $cateogry; ?>"><?php echo $cateogry; ?></option>
16
+ <?php endforeach; ?>
17
+ </optgroup>
18
+ <?php endif; ?>
19
  </select>
20
  </div>
21
 
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.4.1
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  License: GPLv2
@@ -28,6 +28,7 @@ if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
28
  require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-settings.php';
29
  require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-statistics.php';
30
  require_once plugin_dir_path( __FILE__ ) . '/lib/overwrite-sendgrid-methods.php';
 
31
 
32
  // Initialize SendGrid Settings
33
  new Sendgrid_Settings( $plugin );
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.5.0
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  License: GPLv2
28
  require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-settings.php';
29
  require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-statistics.php';
30
  require_once plugin_dir_path( __FILE__ ) . '/lib/overwrite-sendgrid-methods.php';
31
+ require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-smtp.php';
32
 
33
  // Initialize SendGrid Settings
34
  new Sendgrid_Settings( $plugin );