Version Description
- Fix warnings for static method, add notice for php version < 5.3.0, refactor plugin code
=
Download this release
Release Info
Developer | team-rs |
Plugin | SendGrid |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.3 to 1.4
- lib/SendGridSettings.php +0 -154
- lib/SendGridStats.php +0 -142
- lib/class-sendgrid-settings.php +174 -0
- lib/class-sendgrid-statistics.php +135 -0
- lib/class-sendgrid-tools.php +50 -0
- lib/overwrite-sendgrid-methods.php +347 -0
- readme.txt +15 -4
- {lib → vendor}/sendgrid-php/.gitignore +0 -0
- {lib → vendor}/sendgrid-php/.travis.yml +0 -0
- {lib → vendor}/sendgrid-php/MIT.LICENSE +0 -0
- {lib → vendor}/sendgrid-php/Makefile +0 -0
- {lib → vendor}/sendgrid-php/README.md +234 -234
- {lib → vendor}/sendgrid-php/SendGrid.php +44 -44
- {lib → vendor}/sendgrid-php/SendGrid/Api.php +16 -16
- {lib → vendor}/sendgrid-php/SendGrid/Mail.php +721 -721
- {lib → vendor}/sendgrid-php/SendGrid/MailInterface.php +9 -9
- {lib → vendor}/sendgrid-php/SendGrid/Smtp.php +159 -159
- {lib → vendor}/sendgrid-php/SendGrid/Web.php +147 -147
- {lib → vendor}/sendgrid-php/SendGrid_loader.php +13 -13
- {lib → vendor}/sendgrid-php/Test/Mock/Mock_loader.php +13 -13
- {lib → vendor}/sendgrid-php/Test/Mock/SmtpMock.php +13 -13
- {lib → vendor}/sendgrid-php/Test/Mock/WebMock.php +18 -18
- {lib → vendor}/sendgrid-php/Test/SendGrid/ApiTest.php +0 -0
- {lib → vendor}/sendgrid-php/Test/SendGrid/MailTest.php +549 -549
- {lib → vendor}/sendgrid-php/Test/SendGrid/SmtpTest.php +91 -91
- {lib → vendor}/sendgrid-php/Test/SendGrid/WebTest.php +101 -101
- {lib → vendor}/sendgrid-php/Test/SendGridTest.php +0 -0
- {lib → vendor}/sendgrid-php/Test/a_loaderTest.php +7 -7
- {lib → vendor}/sendgrid-php/Test/phpunit.xml +0 -0
- {lib → vendor}/sendgrid-php/composer.json +16 -16
- {lib → vendor}/sendgrid-php/composer.lock +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/animated-overlay.gif +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-icons_222222_256x240.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-icons_2e83ff_256x240.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-icons_454545_256x240.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-icons_888888_256x240.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/images/ui-icons_cd0a0a_256x240.png +0 -0
- view/css/{smoothness → datepicker/smoothness}/jquery-ui-1.10.3.custom.css +0 -0
- view/js/sendgrid.stats.js +59 -59
- view/partials/sendgrid_stats_compliance.php +1 -1
- view/partials/sendgrid_stats_deliveries.php +1 -1
- view/partials/sendgrid_stats_engagement.php +1 -1
- view/partials/sendgrid_stats_widget.php +7 -7
- view/sendgrid_contextual_help.php +82 -0
- view/sendgrid_settings.php +6 -8
- wpsendgrid.php +16 -418
lib/SendGridSettings.php
DELETED
@@ -1,154 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class wpSendGridSettings
|
3 |
-
{
|
4 |
-
public function __construct()
|
5 |
-
{
|
6 |
-
add_action('admin_menu', array(__CLASS__, 'sendgridPluginMenu'));
|
7 |
-
}
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Add settings page
|
11 |
-
*/
|
12 |
-
public function sendgridPluginMenu()
|
13 |
-
{
|
14 |
-
add_options_page(__('SendGrid'), __('SendGrid'), 'manage_options', 'sendgrid-settings.php',
|
15 |
-
array(__CLASS__, 'show_settings_page'));
|
16 |
-
}
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Check username/password
|
20 |
-
*
|
21 |
-
* @param string $username sendgrid username
|
22 |
-
* @param string $password sendgrid password
|
23 |
-
* @return bool
|
24 |
-
*/
|
25 |
-
public static function checkUsernamePassword($username, $password)
|
26 |
-
{
|
27 |
-
$url = "https://sendgrid.com/api/profile.get.json?";
|
28 |
-
$url .= "api_user=". $username . "&api_key=" . $password;
|
29 |
-
|
30 |
-
$ch = curl_init();
|
31 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
32 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
33 |
-
|
34 |
-
$data = curl_exec($ch);
|
35 |
-
curl_close($ch);
|
36 |
-
|
37 |
-
$response = json_decode($data, true);
|
38 |
-
|
39 |
-
if (isset($response['error']))
|
40 |
-
{
|
41 |
-
return false;
|
42 |
-
}
|
43 |
-
|
44 |
-
return true;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Display settings page
|
49 |
-
*/
|
50 |
-
public function show_settings_page()
|
51 |
-
{
|
52 |
-
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
53 |
-
{
|
54 |
-
if (isset($_POST['email_test']) and $_POST['email_test'])
|
55 |
-
{
|
56 |
-
$to = $_POST['sendgrid_to'];
|
57 |
-
$subject = $_POST['sendgrid_subj'];
|
58 |
-
$body = $_POST['sendgrid_body'];
|
59 |
-
$headers = $_POST['sendgrid_headers'];
|
60 |
-
$sent = wp_mail($to, $subject, $body, $headers);
|
61 |
-
if (get_option('sendgrid_api') == 'api')
|
62 |
-
{
|
63 |
-
$sent = json_decode($sent);
|
64 |
-
if ($sent->message == "success")
|
65 |
-
{
|
66 |
-
$message = 'Email sent.';
|
67 |
-
$status = 'updated';
|
68 |
-
}
|
69 |
-
else
|
70 |
-
{
|
71 |
-
$errors = ($sent->errors[0]) ? $sent->errors[0] : $sent;
|
72 |
-
$message = 'Email not sent. ' . $errors;
|
73 |
-
$status = 'error';
|
74 |
-
}
|
75 |
-
|
76 |
-
}
|
77 |
-
elseif (get_option('sendgrid_api') == 'smtp')
|
78 |
-
{
|
79 |
-
if ($sent === true)
|
80 |
-
{
|
81 |
-
$message = 'Email sent.';
|
82 |
-
$status = 'updated';
|
83 |
-
}
|
84 |
-
else
|
85 |
-
{
|
86 |
-
$message = 'Email not sent. ' . $sent;
|
87 |
-
$status = 'error';
|
88 |
-
}
|
89 |
-
}
|
90 |
-
}
|
91 |
-
else
|
92 |
-
{
|
93 |
-
$message = 'Options saved.';
|
94 |
-
$status = 'updated';
|
95 |
-
|
96 |
-
$user = $_POST['sendgrid_user'];
|
97 |
-
update_option('sendgrid_user', $user);
|
98 |
-
|
99 |
-
$password = $_POST['sendgrid_pwd'];
|
100 |
-
update_option('sendgrid_pwd', $password);
|
101 |
-
|
102 |
-
$method = $_POST['sendgrid_api'];
|
103 |
-
if ($method == 'smtp' and !class_exists('Swift'))
|
104 |
-
{
|
105 |
-
$message = 'You must have <a href="http://wordpress.org/plugins/swift-mailer/" target="_blank">' .
|
106 |
-
'Swift-mailer plugin</a> installed and activated';
|
107 |
-
$status = 'error';
|
108 |
-
update_option('sendgrid_api', 'api');
|
109 |
-
}
|
110 |
-
else
|
111 |
-
{
|
112 |
-
update_option('sendgrid_api', $method);
|
113 |
-
}
|
114 |
-
|
115 |
-
$name = $_POST['sendgrid_name'];
|
116 |
-
update_option('sendgrid_from_name', $name);
|
117 |
-
|
118 |
-
$email = $_POST['sendgrid_email'];
|
119 |
-
update_option('sendgrid_from_email', $email);
|
120 |
-
|
121 |
-
$reply_to = $_POST['sendgrid_reply_to'];
|
122 |
-
update_option('sendgrid_reply_to', $reply_to);
|
123 |
-
}
|
124 |
-
}
|
125 |
-
|
126 |
-
$user = get_option('sendgrid_user');
|
127 |
-
$password = get_option('sendgrid_pwd');
|
128 |
-
$method = get_option('sendgrid_api');
|
129 |
-
$name = get_option('sendgrid_from_name');
|
130 |
-
$email = get_option('sendgrid_from_email');
|
131 |
-
$reply_to = get_option('sendgrid_reply_to');
|
132 |
-
|
133 |
-
if ($user and $password)
|
134 |
-
{
|
135 |
-
if (in_array('curl', get_loaded_extensions()))
|
136 |
-
{
|
137 |
-
$valid_credentials = self::checkUsernamePassword($user, $password);
|
138 |
-
|
139 |
-
if (!$valid_credentials)
|
140 |
-
{
|
141 |
-
$message = 'Invalid username/password';
|
142 |
-
$status = 'error';
|
143 |
-
}
|
144 |
-
}
|
145 |
-
else
|
146 |
-
{
|
147 |
-
$message = 'You must have PHP-curl extension enabled';
|
148 |
-
$status = 'error';
|
149 |
-
}
|
150 |
-
}
|
151 |
-
|
152 |
-
require_once dirname(__FILE__) . '/../view/sendgrid_settings.php';
|
153 |
-
}
|
154 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/SendGridStats.php
DELETED
@@ -1,142 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
* Display statistics on dashboard
|
4 |
-
*/
|
5 |
-
|
6 |
-
/**
|
7 |
-
* Verify if SendGrid username and password provided are correct and
|
8 |
-
* initialize function for add widget in dashboard
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
-
*/
|
12 |
-
function my_custom_dashboard_widgets()
|
13 |
-
{
|
14 |
-
$sendgridSettings = new wpSendGridSettings();
|
15 |
-
if (!$sendgridSettings->checkUsernamePassword(get_option('sendgrid_user'), get_option('sendgrid_pwd')))
|
16 |
-
{
|
17 |
-
return;
|
18 |
-
}
|
19 |
-
|
20 |
-
add_meta_box('sendgrid_statistics_widget', 'SendGrid Wordpress Statistics', 'sendgrid_dashboard_statistics', 'dashboard', 'normal', 'high');
|
21 |
-
}
|
22 |
-
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Add widget content to wordpress admin dashboard
|
26 |
-
*
|
27 |
-
* @return void
|
28 |
-
*/
|
29 |
-
function sendgrid_dashboard_statistics()
|
30 |
-
{
|
31 |
-
require plugin_dir_path( __FILE__ ) . '../view/partials/sendgrid_stats_widget.php';
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Add new SendGrid statistics page in wordpress admin menu
|
36 |
-
*
|
37 |
-
* @return void
|
38 |
-
*/
|
39 |
-
function add_dashboard_menu()
|
40 |
-
{
|
41 |
-
$sendgridSettings = new wpSendGridSettings();
|
42 |
-
if (!$sendgridSettings->checkUsernamePassword(get_option('sendgrid_user'), get_option('sendgrid_pwd')))
|
43 |
-
{
|
44 |
-
return;
|
45 |
-
}
|
46 |
-
|
47 |
-
add_dashboard_page( "SendGrid Statistics", "SendGrid Statistics", "manage_options", "sendgrid-statistics", "sendgrid_statistics_page");
|
48 |
-
}
|
49 |
-
add_action('admin_menu', 'add_dashboard_menu');
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Set content for SendGrid statistics page
|
53 |
-
*
|
54 |
-
* @return void
|
55 |
-
*/
|
56 |
-
function sendgrid_statistics_page()
|
57 |
-
{
|
58 |
-
require plugin_dir_path( __FILE__ ) . '../view/sendgrid_stats.php';
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Include javascripts we need for SendGrid statistics page and widget
|
63 |
-
*
|
64 |
-
* @return void;
|
65 |
-
*/
|
66 |
-
function sendgrid_load_script($hook)
|
67 |
-
{
|
68 |
-
if ($hook != "index.php" && $hook != "dashboard_page_sendgrid-statistics")
|
69 |
-
{
|
70 |
-
return;
|
71 |
-
}
|
72 |
-
|
73 |
-
wp_enqueue_script('sendgrid-stats', plugin_dir_url(__FILE__) . '../view/js/sendgrid.stats.js', array('jquery'));
|
74 |
-
wp_enqueue_script('jquery-flot', plugin_dir_url(__FILE__) . '../view/js/jquery.flot.js', array('jquery'));
|
75 |
-
wp_enqueue_script('jquery-flot-time', plugin_dir_url(__FILE__) . '../view/js/jquery.flot.time.js', array('jquery'));
|
76 |
-
wp_enqueue_script('jquery-flot-tofflelegend', plugin_dir_url(__FILE__) . '../view/js/jquery.flot.togglelegend.js', array('jquery'));
|
77 |
-
wp_enqueue_script('jquery-flot-symbol', plugin_dir_url(__FILE__) . '../view/js/jquery.flot.symbol.js', array('jquery'));
|
78 |
-
wp_enqueue_script('jquery-ui-datepicker', plugin_dir_url(__FILE__) . '../view/js/jquery.ui.datepicker.js', array('jquery', 'jquery-ui-core'));
|
79 |
-
wp_enqueue_style('jquery-ui-datepicker', plugin_dir_url(__FILE__) . '../view/css/smoothness/jquery-ui-1.10.3.custom.css');
|
80 |
-
wp_enqueue_style('sendgrid', plugin_dir_url(__FILE__) . '../view/css/sendgrid.css');
|
81 |
-
wp_localize_script('sendgrid-stats', 'sendgrid_vars', array(
|
82 |
-
'sendgrid_nonce' => wp_create_nonce('sendgrid-nonce')
|
83 |
-
));
|
84 |
-
}
|
85 |
-
add_action('admin_enqueue_scripts', 'sendgrid_load_script');
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Get SendGrid stats from API and return JSON response,
|
89 |
-
* this function work like a page and is used for ajax request by javascript functions
|
90 |
-
*
|
91 |
-
* @return void;
|
92 |
-
*/
|
93 |
-
function sendgrid_process_stats()
|
94 |
-
{
|
95 |
-
if (!isset($_POST['sendgrid_nonce']) || !wp_verify_nonce($_POST['sendgrid_nonce'], 'sendgrid-nonce'))
|
96 |
-
{
|
97 |
-
die('Permissions check failed');
|
98 |
-
}
|
99 |
-
|
100 |
-
$parameters = array();
|
101 |
-
$parameters['api_user'] = get_option('sendgrid_user');
|
102 |
-
$parameters['api_key'] = get_option('sendgrid_pwd');
|
103 |
-
$parameters['data_type'] = 'global';
|
104 |
-
$parameters['metric'] = 'all';
|
105 |
-
|
106 |
-
if (array_key_exists('days', $_POST))
|
107 |
-
{
|
108 |
-
$parameters['days'] = $_POST['days'];
|
109 |
-
}
|
110 |
-
else
|
111 |
-
{
|
112 |
-
$parameters['start_date'] = $_POST['start_date'];
|
113 |
-
$parameters['end_date'] = $_POST['end_date'];
|
114 |
-
}
|
115 |
-
|
116 |
-
if ($_POST['type'] and $_POST['type'] == 'wordpress')
|
117 |
-
{
|
118 |
-
$parameters['category'] = 'wp_sendgrid_plugin';
|
119 |
-
}
|
120 |
-
|
121 |
-
echo _processRequest('api/stats.get.json', $parameters);
|
122 |
-
|
123 |
-
die();
|
124 |
-
}
|
125 |
-
add_action('wp_ajax_sendgrid_get_stats', 'sendgrid_process_stats');
|
126 |
-
|
127 |
-
/**
|
128 |
-
* Make cURL request to SendGrid API for required statistics
|
129 |
-
*
|
130 |
-
* @param type $api
|
131 |
-
* @param type $parameters
|
132 |
-
* @return json
|
133 |
-
*/
|
134 |
-
function _processRequest($api = 'api/stats.get.json', $parameters = array())
|
135 |
-
{
|
136 |
-
$data = urldecode(http_build_query($parameters));
|
137 |
-
$process = curl_init();
|
138 |
-
curl_setopt($process, CURLOPT_URL, 'http://sendgrid.com/' . $api . '?' . $data);
|
139 |
-
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
|
140 |
-
|
141 |
-
return curl_exec($process);
|
142 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/class-sendgrid-settings.php
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Sendgrid_Settings
|
4 |
+
{
|
5 |
+
public function __construct( $plugin_directory )
|
6 |
+
{
|
7 |
+
// Add SendGrid settings page in the menu
|
8 |
+
add_action( 'admin_menu', array( __CLASS__, 'add_settings_menu' ) );
|
9 |
+
|
10 |
+
// Add SendGrid settings page in the plugin list
|
11 |
+
add_filter( 'plugin_action_links_' . $plugin_directory, array( __CLASS__, 'add_settings_link' ) );
|
12 |
+
|
13 |
+
// Add SendGrid Help contextual menu in the settings page
|
14 |
+
add_filter( 'contextual_help', array( __CLASS__, 'show_contextual_help' ), 10, 3 );
|
15 |
+
|
16 |
+
// Add SendGrid javascripts in header
|
17 |
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Add SendGrid settings page in the menu
|
22 |
+
*/
|
23 |
+
public static function add_settings_menu()
|
24 |
+
{
|
25 |
+
add_options_page( __( 'SendGrid' ), __( 'SendGrid' ), 'manage_options', 'sendgrid-settings',
|
26 |
+
array( __CLASS__, 'show_settings_page' ));
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Display SendGrid settings page content
|
31 |
+
*/
|
32 |
+
public static function show_settings_page()
|
33 |
+
{
|
34 |
+
if ( 'POST' == $_SERVER['REQUEST_METHOD'] )
|
35 |
+
{
|
36 |
+
if ( isset( $_POST['email_test'] ) and $_POST['email_test'] )
|
37 |
+
{
|
38 |
+
$to = $_POST['sendgrid_to'];
|
39 |
+
$subject = $_POST['sendgrid_subj'];
|
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.';
|
49 |
+
$status = 'updated';
|
50 |
+
} else {
|
51 |
+
$errors = ( $sent->errors[0] ) ? $sent->errors[0] : $sent;
|
52 |
+
$message = 'Email not sent. ' . $errors;
|
53 |
+
$status = 'error';
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
elseif ( 'smtp' == get_option('sendgrid_api') )
|
58 |
+
{
|
59 |
+
if ( true === $sent )
|
60 |
+
{
|
61 |
+
$message = 'Email sent.';
|
62 |
+
$status = 'updated';
|
63 |
+
} else {
|
64 |
+
$message = 'Email not sent. ' . $sent;
|
65 |
+
$status = 'error';
|
66 |
+
}
|
67 |
+
}
|
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 |
+
}
|
100 |
+
|
101 |
+
$user = get_option('sendgrid_user');
|
102 |
+
$password = get_option('sendgrid_pwd');
|
103 |
+
$method = get_option('sendgrid_api');
|
104 |
+
$name = get_option('sendgrid_from_name');
|
105 |
+
$email = get_option('sendgrid_from_email');
|
106 |
+
$reply_to = get_option('sendgrid_reply_to');
|
107 |
+
|
108 |
+
$valid_credentials = false;
|
109 |
+
if ( $user and $password )
|
110 |
+
{
|
111 |
+
if ( in_array( 'curl', get_loaded_extensions() ) )
|
112 |
+
{
|
113 |
+
$valid_credentials = Sendgrid_Tools::check_username_password( $user, $password );
|
114 |
+
|
115 |
+
if ( ! $valid_credentials )
|
116 |
+
{
|
117 |
+
$message = 'Invalid username/password';
|
118 |
+
$status = 'error';
|
119 |
+
}
|
120 |
+
} else {
|
121 |
+
$message = 'You must have PHP-curl extension enabled';
|
122 |
+
$status = 'error';
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
require_once dirname( __FILE__ ) . '/../view/sendgrid_settings.php';
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Add SendGrid settings page in the plugin list
|
131 |
+
*
|
132 |
+
* @param mixed $links links
|
133 |
+
* @return mixed links
|
134 |
+
*/
|
135 |
+
public static function add_settings_link( $links )
|
136 |
+
{
|
137 |
+
$settings_link = '<a href="options-general.php?page=sendgrid-settings.php">Settings</a>';
|
138 |
+
array_unshift( $links, $settings_link );
|
139 |
+
|
140 |
+
return $links;
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Add SendGrid Help contextual menu in the settings page
|
145 |
+
*
|
146 |
+
* @param mixed $contextual_help contextual help
|
147 |
+
* @param integer $screen_id screen id
|
148 |
+
* @param integer $screen screen
|
149 |
+
* @return string
|
150 |
+
*/
|
151 |
+
public static function show_contextual_help( $contextual_help, $screen_id, $screen )
|
152 |
+
{
|
153 |
+
if ( SENDGRID_PLUGIN_STATISTICS == $screen_id or SENDGRID_PLUGIN_SETTINGS == $screen_id )
|
154 |
+
{
|
155 |
+
$contextual_help = file_get_contents( dirname( __FILE__ ) . '/../view/sendgrid_contextual_help.php' );
|
156 |
+
}
|
157 |
+
|
158 |
+
return $contextual_help;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Include css & javascripts we need for SendGrid settings page and widget
|
163 |
+
*
|
164 |
+
* @return void;
|
165 |
+
*/
|
166 |
+
public static function add_headers( $hook )
|
167 |
+
{
|
168 |
+
if ( SENDGRID_PLUGIN_SETTINGS != $hook ) {
|
169 |
+
return;
|
170 |
+
}
|
171 |
+
|
172 |
+
wp_enqueue_style( 'sendgrid', plugin_dir_url( __FILE__ ) . '../view/css/sendgrid.css' );
|
173 |
+
}
|
174 |
+
}
|
lib/class-sendgrid-statistics.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Sendgrid_Statistics
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
// Add SendGrid widget in dashboard
|
8 |
+
add_action( 'wp_dashboard_setup', array( __CLASS__, 'add_dashboard_widget' ) );
|
9 |
+
|
10 |
+
// Add SendGrid stats page in menu
|
11 |
+
add_action( 'admin_menu', array( __CLASS__, 'add_statistics_menu' ) );
|
12 |
+
|
13 |
+
// Add SendGrid javascripts in header
|
14 |
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
|
15 |
+
|
16 |
+
// Add SendGrid page for get statistics through ajax
|
17 |
+
add_action( 'wp_ajax_sendgrid_get_stats', array( __CLASS__, 'get_ajax_statistics' ) );
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Verify if SendGrid username and password provided are correct and
|
22 |
+
* initialize function for add widget in dashboard
|
23 |
+
*
|
24 |
+
* @return void
|
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 |
+
|
32 |
+
add_meta_box( 'sendgrid_statistics_widget', 'SendGrid Wordpress Statistics', array( __CLASS__, 'show_dashboard_widget' ),
|
33 |
+
'dashboard', 'normal', 'high' );
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Display SendGrid widget content
|
38 |
+
*
|
39 |
+
* @return void
|
40 |
+
*/
|
41 |
+
public static function show_dashboard_widget()
|
42 |
+
{
|
43 |
+
require plugin_dir_path( __FILE__ ) . '../view/partials/sendgrid_stats_widget.php';
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Add SendGrid statistics page in the menu
|
48 |
+
*
|
49 |
+
* @return void
|
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 |
+
|
57 |
+
add_dashboard_page( "SendGrid Statistics", "SendGrid Statistics", "manage_options", "sendgrid-statistics",
|
58 |
+
array( __CLASS__, "show_statistics_page" ) );
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Display SendGrid statistics page
|
63 |
+
*
|
64 |
+
* @return void
|
65 |
+
*/
|
66 |
+
public static function show_statistics_page()
|
67 |
+
{
|
68 |
+
require plugin_dir_path( __FILE__ ) . '../view/sendgrid_stats.php';
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Include css & javascripts we need for SendGrid statistics page and widget
|
73 |
+
*
|
74 |
+
* @return void;
|
75 |
+
*/
|
76 |
+
public static function add_headers( $hook )
|
77 |
+
{
|
78 |
+
if ( "index.php" != $hook && SENDGRID_PLUGIN_STATISTICS != $hook ) {
|
79 |
+
return;
|
80 |
+
}
|
81 |
+
|
82 |
+
// Javascript
|
83 |
+
wp_enqueue_script( 'sendgrid-stats', plugin_dir_url( __FILE__ ) . '../view/js/sendgrid.stats.js', array('jquery') );
|
84 |
+
wp_enqueue_script( 'jquery-flot', plugin_dir_url( __FILE__ ) . '../view/js/jquery.flot.js', array('jquery') );
|
85 |
+
wp_enqueue_script( 'jquery-flot-time', plugin_dir_url( __FILE__ ) . '../view/js/jquery.flot.time.js', array('jquery') );
|
86 |
+
wp_enqueue_script( 'jquery-flot-tofflelegend', plugin_dir_url( __FILE__ ) . '../view/js/jquery.flot.togglelegend.js', array('jquery') );
|
87 |
+
wp_enqueue_script( 'jquery-flot-symbol', plugin_dir_url( __FILE__ ) . '../view/js/jquery.flot.symbol.js', array('jquery') );
|
88 |
+
wp_enqueue_script('jquery-ui-datepicker', plugin_dir_url( __FILE__ ) . '../view/js/jquery.ui.datepicker.js', array('jquery', 'jquery-ui-core') );
|
89 |
+
|
90 |
+
// CSS
|
91 |
+
wp_enqueue_style( 'jquery-ui-datepicker', plugin_dir_url( __FILE__ ) . '../view/css/datepicker/smoothness/jquery-ui-1.10.3.custom.css' );
|
92 |
+
wp_enqueue_style( 'sendgrid', plugin_dir_url( __FILE__ ) . '../view/css/sendgrid.css' );
|
93 |
+
|
94 |
+
wp_localize_script( 'sendgrid-stats', 'sendgrid_vars',
|
95 |
+
array(
|
96 |
+
'sendgrid_nonce' => wp_create_nonce('sendgrid-nonce')
|
97 |
+
)
|
98 |
+
);
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Get SendGrid stats from API and return JSON response,
|
103 |
+
* this function work like a page and is used for ajax request by javascript functions
|
104 |
+
*
|
105 |
+
* @return void;
|
106 |
+
*/
|
107 |
+
public static function get_ajax_statistics()
|
108 |
+
{
|
109 |
+
if ( ! isset( $_POST['sendgrid_nonce'] ) || ! wp_verify_nonce( $_POST['sendgrid_nonce'], 'sendgrid-nonce') ) {
|
110 |
+
die( 'Permissions check failed' );
|
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 |
+
|
119 |
+
if ( array_key_exists( 'days', $_POST ) ) {
|
120 |
+
$parameters['days'] = $_POST['days'];
|
121 |
+
} else {
|
122 |
+
$parameters['start_date'] = $_POST['start_date'];
|
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 );
|
131 |
+
|
132 |
+
die();
|
133 |
+
}
|
134 |
+
|
135 |
+
}
|
lib/class-sendgrid-tools.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Sendgrid_Tools
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Check username/password
|
7 |
+
*
|
8 |
+
* @param string $username sendgrid username
|
9 |
+
* @param string $password sendgrid password
|
10 |
+
* @return bool
|
11 |
+
*/
|
12 |
+
public static function check_username_password( $username, $password )
|
13 |
+
{
|
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 |
+
{
|
28 |
+
return false;
|
29 |
+
}
|
30 |
+
|
31 |
+
return true;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Make cURL request to SendGrid API
|
36 |
+
*
|
37 |
+
* @param type $api
|
38 |
+
* @param type $parameters
|
39 |
+
* @return json
|
40 |
+
*/
|
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 |
+
}
|
lib/overwrite-sendgrid-methods.php
ADDED
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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 |
+
*
|
14 |
+
* A true return value does not automatically mean that the user received the
|
15 |
+
* email successfully. It just only means that the method used was able to
|
16 |
+
* process the request without any errors.
|
17 |
+
*
|
18 |
+
* Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
|
19 |
+
* creating a from address like 'Name <email@address.com>' when both are set. If
|
20 |
+
* just 'wp_mail_from' is set, then just the email address will be used with no
|
21 |
+
* name.
|
22 |
+
*
|
23 |
+
* The default content type is 'text/plain' which does not allow using HTML.
|
24 |
+
* However, you can set the content type of the email by using the
|
25 |
+
* 'wp_mail_content_type' filter.
|
26 |
+
*
|
27 |
+
* The default charset is based on the charset used on the blog. The charset can
|
28 |
+
* be set using the 'wp_mail_charset' filter.
|
29 |
+
*
|
30 |
+
* @since 1.2.1
|
31 |
+
* @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
|
32 |
+
* @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
|
33 |
+
* @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
|
34 |
+
* @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
|
35 |
+
* @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
|
36 |
+
*
|
37 |
+
* @param string|array $to Array or comma-separated list of email addresses to send message.
|
38 |
+
* @param string $subject Email subject
|
39 |
+
* @param string $message Message contents
|
40 |
+
* @param string|array $headers Optional. Additional headers.
|
41 |
+
* @param string|array $attachments Optional. Files to attach.
|
42 |
+
* @return bool Whether the email contents were sent successfully.
|
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' ) ) );
|
52 |
+
|
53 |
+
// prepare attachments
|
54 |
+
$attached_files = array();
|
55 |
+
if ( ! empty( $attachments ) )
|
56 |
+
{
|
57 |
+
if ( ! is_array( $attachments ) )
|
58 |
+
{
|
59 |
+
$pos = strpos( ',', $attachments );
|
60 |
+
if ( false !== $pos )
|
61 |
+
{
|
62 |
+
$attachments = preg_split( '/,\s*/', $attachments );
|
63 |
+
} else {
|
64 |
+
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( is_array( $attachments ) ) {
|
69 |
+
foreach ( $attachments as $attachment ) {
|
70 |
+
if ( file_exists( $attachment ) ) {
|
71 |
+
$attached_files[] = $attachment;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
// Headers
|
78 |
+
$cc = array();
|
79 |
+
$bcc = array();
|
80 |
+
if ( empty( $headers ) ) {
|
81 |
+
$headers = array();
|
82 |
+
} else {
|
83 |
+
if ( ! is_array( $headers ) ) {
|
84 |
+
// Explode the headers out, so this function can take both
|
85 |
+
// string headers and an array of headers.
|
86 |
+
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
|
87 |
+
} else {
|
88 |
+
$tempheaders = $headers;
|
89 |
+
}
|
90 |
+
$headers = array();
|
91 |
+
|
92 |
+
// If it's actually got contents
|
93 |
+
if ( ! empty( $tempheaders ) ) {
|
94 |
+
// Iterate through the raw headers
|
95 |
+
foreach ( (array) $tempheaders as $header ) {
|
96 |
+
if ( false === strpos($header, ':') ) {
|
97 |
+
if ( false !== stripos( $header, 'boundary=' ) ) {
|
98 |
+
$parts = preg_split( '/boundary=/i', trim( $header ) );
|
99 |
+
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
|
100 |
+
}
|
101 |
+
continue;
|
102 |
+
}
|
103 |
+
// Explode them out
|
104 |
+
list( $name, $content ) = explode( ':', trim( $header ), 2 );
|
105 |
+
|
106 |
+
// Cleanup crew
|
107 |
+
$name = trim( $name );
|
108 |
+
$content = trim( $content );
|
109 |
+
|
110 |
+
switch ( strtolower( $name ) ) {
|
111 |
+
// Mainly for legacy -- process a From: header if it's there
|
112 |
+
case 'from':
|
113 |
+
if ( false !== strpos( $content, '<' ) ) {
|
114 |
+
// So... making my life hard again?
|
115 |
+
$from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
|
116 |
+
$from_name = str_replace( '"', '', $from_name );
|
117 |
+
$from_name = trim( $from_name );
|
118 |
+
|
119 |
+
$from_email = substr( $content, strpos( $content, '<' ) + 1 );
|
120 |
+
$from_email = str_replace( '>', '', $from_email );
|
121 |
+
$from_email = trim( $from_email );
|
122 |
+
} else {
|
123 |
+
$from_email = trim( $content );
|
124 |
+
}
|
125 |
+
break;
|
126 |
+
case 'content-type':
|
127 |
+
if ( false !== strpos( $content, ';' ) ) {
|
128 |
+
list( $type, $charset ) = explode( ';', $content );
|
129 |
+
$content_type = trim( $type );
|
130 |
+
if ( false !== stripos( $charset, 'charset=' ) ) {
|
131 |
+
$charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
|
132 |
+
} elseif ( false !== stripos( $charset, 'boundary=' ) ) {
|
133 |
+
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
|
134 |
+
$charset = '';
|
135 |
+
}
|
136 |
+
} else {
|
137 |
+
$content_type = trim( $content );
|
138 |
+
}
|
139 |
+
break;
|
140 |
+
case 'cc':
|
141 |
+
$cc = array_merge( (array) $cc, explode( ',', $content ) );
|
142 |
+
foreach ( $cc as $key => $recipient )
|
143 |
+
{
|
144 |
+
$cc[ $key ] = trim( $recipient );
|
145 |
+
}
|
146 |
+
break;
|
147 |
+
case 'bcc':
|
148 |
+
$bcc = array_merge( (array) $bcc, explode( ',', $content ) );
|
149 |
+
foreach ( $bcc as $key => $recipient )
|
150 |
+
{
|
151 |
+
$bcc[ $key ] = trim( $recipient );
|
152 |
+
}
|
153 |
+
break;
|
154 |
+
case 'reply-to':
|
155 |
+
$replyto = $content;
|
156 |
+
break;
|
157 |
+
default:
|
158 |
+
// Add it to our grand headers array
|
159 |
+
$headers[trim( $name )] = trim( $content );
|
160 |
+
break;
|
161 |
+
}
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
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
|
173 |
+
* there's no easy alternative. Defaulting to admin_email might appear to be another
|
174 |
+
* option but some hosts may refuse to relay mail from an unknown domain. See
|
175 |
+
* http://trac.wordpress.org/ticket/5007.
|
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.
|
183 |
+
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
|
184 |
+
if ( 'www.' == substr( $sitename, 0, 4 ) ) {
|
185 |
+
$sitename = substr( $sitename, 4 );
|
186 |
+
}
|
187 |
+
|
188 |
+
$from_email = "wordpress@$sitename";
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
// Plugin authors can override the potentially troublesome default
|
193 |
+
$from_email = apply_filters( 'wp_mail_from' , $from_email );
|
194 |
+
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
195 |
+
|
196 |
+
// Set destination addresses
|
197 |
+
if ( !is_array( $to ) )
|
198 |
+
$to = explode( ',', $to );
|
199 |
+
|
200 |
+
// Add any CC and BCC recipients
|
201 |
+
if ( ! empty( $cc ) )
|
202 |
+
{
|
203 |
+
foreach ( (array) $cc as $key => $recipient )
|
204 |
+
{
|
205 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
206 |
+
if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) )
|
207 |
+
{
|
208 |
+
if ( count( $matches ) == 3 )
|
209 |
+
{
|
210 |
+
$cc[ $key ] = trim( $matches[2] );
|
211 |
+
}
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
if ( ! empty( $bcc ) ) {
|
217 |
+
foreach ( (array) $bcc as $key => $recipient ) {
|
218 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
219 |
+
if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
|
220 |
+
if ( 3 == count( $matches ) )
|
221 |
+
{
|
222 |
+
$bcc[ $key ] = trim( $matches[2] );
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
if ( ( 'api' == $method ) and ( count( $cc ) or count( $bcc ) ) )
|
229 |
+
{
|
230 |
+
foreach ( (array) $to as $key => $recipient )
|
231 |
+
{
|
232 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
233 |
+
if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) )
|
234 |
+
{
|
235 |
+
if ( 3 == count( $matches ) ) {
|
236 |
+
$to[ $key ] = trim( $matches[2] );
|
237 |
+
}
|
238 |
+
}
|
239 |
+
}
|
240 |
+
}
|
241 |
+
// Set Content-Type and charset
|
242 |
+
// If we don't have a content-type from the input headers
|
243 |
+
if ( ! isset( $content_type ) )
|
244 |
+
$content_type = 'text/plain';
|
245 |
+
|
246 |
+
$content_type = apply_filters( 'wp_mail_content_type', $content_type );
|
247 |
+
|
248 |
+
$mail->setTos( $to )
|
249 |
+
->setSubject( $subject )
|
250 |
+
->setText( $message )
|
251 |
+
->setCategory( SENDGRID_CATEGORY )
|
252 |
+
->setFrom( $from_email );
|
253 |
+
|
254 |
+
// send HTML content
|
255 |
+
if ( 'text/plain' !== $content_type )
|
256 |
+
{
|
257 |
+
$mail->setHtml( $message );
|
258 |
+
}
|
259 |
+
// set from name
|
260 |
+
if ( $from_email )
|
261 |
+
{
|
262 |
+
$mail->setFromName( $from_name );
|
263 |
+
}
|
264 |
+
// set from cc
|
265 |
+
if ( count( $cc ) )
|
266 |
+
{
|
267 |
+
$mail->setCcs( $cc );
|
268 |
+
}
|
269 |
+
// set from bcc
|
270 |
+
if ( count( $bcc ) )
|
271 |
+
{
|
272 |
+
$mail->setBccs( $bcc );
|
273 |
+
}
|
274 |
+
if ( ! isset( $replyto ) )
|
275 |
+
{
|
276 |
+
$replyto = trim( get_option('sendgrid_reply_to') );
|
277 |
+
}
|
278 |
+
$reply_to_found = preg_match( '/.*<(.*)>.*/i', $replyto, $result );
|
279 |
+
if ( $reply_to_found )
|
280 |
+
{
|
281 |
+
$replyto = $result[1];
|
282 |
+
}
|
283 |
+
$mail->setReplyTo( $replyto );
|
284 |
+
|
285 |
+
// add attachemnts
|
286 |
+
if ( count( $attached_files ) )
|
287 |
+
{
|
288 |
+
$mail->setAttachments( $attached_files );
|
289 |
+
}
|
290 |
+
|
291 |
+
// Send!
|
292 |
+
try
|
293 |
+
{
|
294 |
+
if ( 'api' == $method )
|
295 |
+
{
|
296 |
+
return $sendgrid->web->send( $mail );
|
297 |
+
}
|
298 |
+
elseif ( 'smtp' == $method )
|
299 |
+
{
|
300 |
+
if ( class_exists('Swift') )
|
301 |
+
{
|
302 |
+
return $sendgrid->smtp->send( $mail );
|
303 |
+
}
|
304 |
+
else
|
305 |
+
{
|
306 |
+
return 'Error: Swift Class not loaded. Please activate Swift plugin or use API.';
|
307 |
+
}
|
308 |
+
}
|
309 |
+
}
|
310 |
+
catch ( Exception $e )
|
311 |
+
{
|
312 |
+
return $e->getMessage();
|
313 |
+
}
|
314 |
+
|
315 |
+
return false;
|
316 |
+
}
|
317 |
+
}
|
318 |
+
else
|
319 |
+
{
|
320 |
+
/**
|
321 |
+
* wp_mail has been declared by another process or plugin, so you won't be able to use SENDGRID until the problem is solved.
|
322 |
+
*/
|
323 |
+
add_action( 'admin_notices', 'wp_mail_already_declared_notice' );
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Display the notice that wp_mail function was declared by another plugin
|
327 |
+
*
|
328 |
+
* return void
|
329 |
+
*/
|
330 |
+
function wp_mail_already_declared_notice()
|
331 |
+
{
|
332 |
+
echo '<div class="error"><p>' . __( 'SendGrid: wp_mail has been declared by another process or plugin, so you won\'t be able to use SendGrid until the conflict is solved.' ) . '</p></div>';
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
if ( ! function_exists('set_html_content_type') )
|
337 |
+
{
|
338 |
+
/**
|
339 |
+
* Return the content type used to send html emails
|
340 |
+
*
|
341 |
+
* return string Conteny-type needed to send HTML emails
|
342 |
+
*/
|
343 |
+
function set_html_content_type()
|
344 |
+
{
|
345 |
+
return 'text/html';
|
346 |
+
}
|
347 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ 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: 3.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -69,7 +69,10 @@ remove_filter('wp_mail_content_type', 'set_html_content_type');`
|
|
69 |
|
70 |
== Installation ==
|
71 |
|
72 |
-
|
|
|
|
|
|
|
73 |
|
74 |
To upload the SendGrid Plugin .ZIP file:
|
75 |
|
@@ -120,6 +123,12 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
|
|
120 |
* Fix errors: set_html_content_type error, WP_DEBUG enabled notice, Reply-To header is overwritten by default option
|
121 |
= 1.3 =
|
122 |
* Added support for Wordpress 3.8, fixed visual issues for Wordpress 3.7
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
== Upgrade notice ==
|
125 |
|
@@ -128,4 +137,6 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
|
|
128 |
= 1.2 =
|
129 |
* Now you can switch between Sendgrid general statistics and Sendgrid wordpress statistics.
|
130 |
= 1.3 =
|
131 |
-
* Added support for Wordpress 3.8, fixed visual issues for Wordpress 3.7
|
|
|
|
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: 3.9
|
7 |
+
Stable tag: 1.4.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
69 |
|
70 |
== Installation ==
|
71 |
|
72 |
+
Requirements:
|
73 |
+
1. PHP version >= 5.3.0
|
74 |
+
2. You need to have PHP-curl extension enabled.
|
75 |
+
3. To send emails through SMTP you need to install also the 'Swift Mailer' plugin. After installing 'Swift Mailer' plugin, you must have PHP-short_open_tag setting enabled in your php.ini file.
|
76 |
|
77 |
To upload the SendGrid Plugin .ZIP file:
|
78 |
|
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 |
|
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
|
{lib → vendor}/sendgrid-php/.gitignore
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/.travis.yml
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/MIT.LICENSE
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/Makefile
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/README.md
RENAMED
@@ -1,234 +1,234 @@
|
|
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 |
-
...
|
192 |
-
setHtml("Hey %name%, you work at %place%")->
|
193 |
-
addSubstitution("%name%", array("John", "Harry", "Bob"))->
|
194 |
-
addSubstitution("%place%", array("%office%", "%office%", "%home%"))->
|
195 |
-
addSection("%office%", "an office")->
|
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 |
+
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 |
+
...
|
192 |
+
setHtml("Hey %name%, you work at %place%")->
|
193 |
+
addSubstitution("%name%", array("John", "Harry", "Bob"))->
|
194 |
+
addSubstitution("%place%", array("%office%", "%office%", "%home%"))->
|
195 |
+
addSection("%office%", "an office")->
|
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 |
+
```
|
{lib → vendor}/sendgrid-php/SendGrid.php
RENAMED
@@ -1,44 +1,44 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/SendGrid/Api.php
RENAMED
@@ -1,17 +1,17 @@
|
|
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 |
}
|
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 |
}
|
{lib → vendor}/sendgrid-php/SendGrid/Mail.php
RENAMED
@@ -1,721 +1,721 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/SendGrid/MailInterface.php
RENAMED
@@ -1,10 +1,10 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace SendGrid;
|
4 |
-
|
5 |
-
interface MailInterface
|
6 |
-
{
|
7 |
-
public function send(Mail $mail);
|
8 |
-
|
9 |
-
|
10 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace SendGrid;
|
4 |
+
|
5 |
+
interface MailInterface
|
6 |
+
{
|
7 |
+
public function send(Mail $mail);
|
8 |
+
|
9 |
+
|
10 |
}
|
{lib → vendor}/sendgrid-php/SendGrid/Smtp.php
RENAMED
@@ -1,159 +1,159 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace SendGrid;
|
4 |
-
|
5 |
-
class Smtp extends Api implements MailInterface
|
6 |
-
{
|
7 |
-
//the available ports
|
8 |
-
const TLS = 587;
|
9 |
-
const TLS_ALTERNATIVE = 25;
|
10 |
-
const SSL = 465;
|
11 |
-
|
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 |
-
{
|
18 |
-
/* check for SwiftMailer,
|
19 |
-
* if it doesn't exist, try loading
|
20 |
-
* it from Pear
|
21 |
-
*/
|
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;
|
29 |
-
}
|
30 |
-
|
31 |
-
/* setPort
|
32 |
-
* set the SMTP outgoing port number
|
33 |
-
* @param Int $port - the port number to use
|
34 |
-
* @return the SMTP object
|
35 |
-
*/
|
36 |
-
public function setPort($port)
|
37 |
-
{
|
38 |
-
$this->port = $port;
|
39 |
-
|
40 |
-
return $this;
|
41 |
-
}
|
42 |
-
|
43 |
-
/* _getSwiftInstance
|
44 |
-
* initialize and return the swift transport instance
|
45 |
-
* @return the Swift_Mailer instance
|
46 |
-
*/
|
47 |
-
private function _getSwiftInstance($port)
|
48 |
-
{
|
49 |
-
if (!isset($this->swift_instances[$port]))
|
50 |
-
{
|
51 |
-
$transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', $port);
|
52 |
-
$transport->setUsername($this->username);
|
53 |
-
$transport->setPassword($this->password);
|
54 |
-
|
55 |
-
$swift = \Swift_Mailer::newInstance($transport);
|
56 |
-
|
57 |
-
$this->swift_instances[$port] = $swift;
|
58 |
-
}
|
59 |
-
|
60 |
-
return $this->swift_instances[$port];
|
61 |
-
}
|
62 |
-
|
63 |
-
/* _mapToSwift
|
64 |
-
* Maps the SendGridMail Object to the SwiftMessage object
|
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 |
-
|
72 |
-
/*
|
73 |
-
* Since we're sending transactional email, we want the message to go to one person at a time, rather
|
74 |
-
* than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
|
75 |
-
* but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
|
76 |
-
* ignored anyway.
|
77 |
-
*/
|
78 |
-
$message->setTo($mail->getFrom());
|
79 |
-
$message->setFrom($mail->getFrom(true));
|
80 |
-
$message->setCc($mail->getCcs());
|
81 |
-
$message->setBcc($mail->getBccs());
|
82 |
-
|
83 |
-
if ($mail->getHtml())
|
84 |
-
{
|
85 |
-
$message->setBody($mail->getHtml(), 'text/html');
|
86 |
-
if ($mail->getText()) $message->addPart($mail->getText(), 'text/plain');
|
87 |
-
}
|
88 |
-
else
|
89 |
-
{
|
90 |
-
$message->setBody($mail->getText(), 'text/plain');
|
91 |
-
}
|
92 |
-
|
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
|
129 |
-
if ($attachments)
|
130 |
-
{
|
131 |
-
foreach ($attachments as $attachment)
|
132 |
-
{
|
133 |
-
$message->attach(\Swift_Attachment::fromPath($attachment['file']));
|
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 |
-
|
144 |
-
/* send
|
145 |
-
* Send the Mail Message
|
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 |
-
|
153 |
-
$message = $this->_mapToSwift($mail);
|
154 |
-
|
155 |
-
$swift->send($message, $failures);
|
156 |
-
|
157 |
-
return true;
|
158 |
-
}
|
159 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace SendGrid;
|
4 |
+
|
5 |
+
class Smtp extends Api implements MailInterface
|
6 |
+
{
|
7 |
+
//the available ports
|
8 |
+
const TLS = 587;
|
9 |
+
const TLS_ALTERNATIVE = 25;
|
10 |
+
const SSL = 465;
|
11 |
+
|
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 |
+
{
|
18 |
+
/* check for SwiftMailer,
|
19 |
+
* if it doesn't exist, try loading
|
20 |
+
* it from Pear
|
21 |
+
*/
|
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;
|
29 |
+
}
|
30 |
+
|
31 |
+
/* setPort
|
32 |
+
* set the SMTP outgoing port number
|
33 |
+
* @param Int $port - the port number to use
|
34 |
+
* @return the SMTP object
|
35 |
+
*/
|
36 |
+
public function setPort($port)
|
37 |
+
{
|
38 |
+
$this->port = $port;
|
39 |
+
|
40 |
+
return $this;
|
41 |
+
}
|
42 |
+
|
43 |
+
/* _getSwiftInstance
|
44 |
+
* initialize and return the swift transport instance
|
45 |
+
* @return the Swift_Mailer instance
|
46 |
+
*/
|
47 |
+
private function _getSwiftInstance($port)
|
48 |
+
{
|
49 |
+
if (!isset($this->swift_instances[$port]))
|
50 |
+
{
|
51 |
+
$transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', $port);
|
52 |
+
$transport->setUsername($this->username);
|
53 |
+
$transport->setPassword($this->password);
|
54 |
+
|
55 |
+
$swift = \Swift_Mailer::newInstance($transport);
|
56 |
+
|
57 |
+
$this->swift_instances[$port] = $swift;
|
58 |
+
}
|
59 |
+
|
60 |
+
return $this->swift_instances[$port];
|
61 |
+
}
|
62 |
+
|
63 |
+
/* _mapToSwift
|
64 |
+
* Maps the SendGridMail Object to the SwiftMessage object
|
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 |
+
|
72 |
+
/*
|
73 |
+
* Since we're sending transactional email, we want the message to go to one person at a time, rather
|
74 |
+
* than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
|
75 |
+
* but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
|
76 |
+
* ignored anyway.
|
77 |
+
*/
|
78 |
+
$message->setTo($mail->getFrom());
|
79 |
+
$message->setFrom($mail->getFrom(true));
|
80 |
+
$message->setCc($mail->getCcs());
|
81 |
+
$message->setBcc($mail->getBccs());
|
82 |
+
|
83 |
+
if ($mail->getHtml())
|
84 |
+
{
|
85 |
+
$message->setBody($mail->getHtml(), 'text/html');
|
86 |
+
if ($mail->getText()) $message->addPart($mail->getText(), 'text/plain');
|
87 |
+
}
|
88 |
+
else
|
89 |
+
{
|
90 |
+
$message->setBody($mail->getText(), 'text/plain');
|
91 |
+
}
|
92 |
+
|
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
|
129 |
+
if ($attachments)
|
130 |
+
{
|
131 |
+
foreach ($attachments as $attachment)
|
132 |
+
{
|
133 |
+
$message->attach(\Swift_Attachment::fromPath($attachment['file']));
|
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 |
+
|
144 |
+
/* send
|
145 |
+
* Send the Mail Message
|
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 |
+
|
153 |
+
$message = $this->_mapToSwift($mail);
|
154 |
+
|
155 |
+
$swift->send($message, $failures);
|
156 |
+
|
157 |
+
return true;
|
158 |
+
}
|
159 |
+
}
|
{lib → vendor}/sendgrid-php/SendGrid/Web.php
RENAMED
@@ -1,147 +1,147 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/SendGrid_loader.php
RENAMED
@@ -1,14 +1,14 @@
|
|
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");
|
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");
|
{lib → vendor}/sendgrid-php/Test/Mock/Mock_loader.php
RENAMED
@@ -1,14 +1,14 @@
|
|
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");
|
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");
|
{lib → vendor}/sendgrid-php/Test/Mock/SmtpMock.php
RENAMED
@@ -1,14 +1,14 @@
|
|
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 |
}
|
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 |
}
|
{lib → vendor}/sendgrid-php/Test/Mock/WebMock.php
RENAMED
@@ -1,19 +1,19 @@
|
|
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 |
}
|
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 |
}
|
{lib → vendor}/sendgrid-php/Test/SendGrid/ApiTest.php
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/Test/SendGrid/MailTest.php
RENAMED
@@ -1,549 +1,549 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/Test/SendGrid/SmtpTest.php
RENAMED
@@ -1,91 +1,91 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/Test/SendGrid/WebTest.php
RENAMED
@@ -1,101 +1,101 @@
|
|
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("¶m[]=foo¶m[]=bar¶m[]=car¶m[]=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 |
-
}
|
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("¶m[]=foo¶m[]=bar¶m[]=car¶m[]=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 |
+
}
|
{lib → vendor}/sendgrid-php/Test/SendGridTest.php
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/Test/a_loaderTest.php
RENAMED
@@ -1,7 +1,7 @@
|
|
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";
|
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";
|
{lib → vendor}/sendgrid-php/Test/phpunit.xml
RENAMED
File without changes
|
{lib → vendor}/sendgrid-php/composer.json
RENAMED
@@ -1,16 +1,16 @@
|
|
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 |
-
}
|
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 |
+
}
|
{lib → vendor}/sendgrid-php/composer.lock
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/animated-overlay.gif
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_flat_0_aaaaaa_40x100.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_flat_75_ffffff_40x100.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_55_fbf9ee_1x400.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_65_ffffff_1x400.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_75_dadada_1x400.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_75_e6e6e6_1x400.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_glass_95_fef1ec_1x400.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-bg_highlight-soft_75_cccccc_1x100.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-icons_222222_256x240.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-icons_2e83ff_256x240.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-icons_454545_256x240.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-icons_888888_256x240.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/images/ui-icons_cd0a0a_256x240.png
RENAMED
File without changes
|
view/css/{smoothness → datepicker/smoothness}/jquery-ui-1.10.3.custom.css
RENAMED
File without changes
|
view/js/sendgrid.stats.js
CHANGED
@@ -155,69 +155,69 @@ jQuery(document).ready(function($) {
|
|
155 |
dropStats.push([date, dropsThisDay]);
|
156 |
blockStats.push([date, blocksThisDay]);
|
157 |
});
|
158 |
-
|
159 |
-
/* Prepare data for charts */
|
160 |
-
var dataDeliveries = [
|
161 |
-
{
|
162 |
-
label : 'Requests',
|
163 |
-
data : requestStats,
|
164 |
-
points: { symbol: "circle" }
|
165 |
-
},
|
166 |
-
{
|
167 |
-
label : 'Drops',
|
168 |
-
data : dropStats,
|
169 |
-
points: { symbol: "square" }
|
170 |
-
},
|
171 |
-
{
|
172 |
-
label : 'Delivered',
|
173 |
-
data : deliveredStats,
|
174 |
-
points: { symbol: "diamond" }
|
175 |
-
}];
|
176 |
-
|
177 |
-
var dataCompliance = [
|
178 |
-
{
|
179 |
-
label : 'Spam reports',
|
180 |
-
data : spamreportStats,
|
181 |
-
points: { symbol: "circle" }
|
182 |
-
},
|
183 |
-
{
|
184 |
-
label : 'Bounces',
|
185 |
-
data : bounceStats,
|
186 |
-
points: { symbol: "square" }
|
187 |
-
},
|
188 |
-
{
|
189 |
-
label : 'Blocked',
|
190 |
-
data : blockStats,
|
191 |
-
points: { symbol: "diamond" }
|
192 |
-
}
|
193 |
-
];
|
194 |
-
|
195 |
-
var dataEngagement = [
|
196 |
-
{
|
197 |
-
label : 'Unsubscribes',
|
198 |
-
data : unsubscribeStats,
|
199 |
-
points: { symbol: "diamond" }
|
200 |
-
},
|
201 |
-
{
|
202 |
-
label : 'Unique Opens',
|
203 |
-
data : uniqueOpenStats,
|
204 |
-
points: { symbol: "triangle" }
|
205 |
-
},
|
206 |
-
{
|
207 |
-
label : 'Opens',
|
208 |
-
data : openStats,
|
209 |
-
points: { symbol: "square" }
|
210 |
-
},
|
211 |
-
{
|
212 |
-
label : 'Clicks',
|
213 |
-
data : clickStats,
|
214 |
-
points: { symbol: "cross" }
|
215 |
-
}
|
216 |
-
];
|
217 |
|
218 |
/* Show charts only on SendGrid Statistics page */
|
219 |
if (filterType === "sendgrid-statistics")
|
220 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
showChart("#deliveries-container", "#deliveries-container-legend", startDate,
|
222 |
endDate, dataDeliveries, ["#328701", "#bcd516", "#fba617"]);
|
223 |
showChart("#compliance-container", "#compliance-container-legend", startDate,
|
155 |
dropStats.push([date, dropsThisDay]);
|
156 |
blockStats.push([date, blocksThisDay]);
|
157 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
/* Show charts only on SendGrid Statistics page */
|
160 |
if (filterType === "sendgrid-statistics")
|
161 |
{
|
162 |
+
/* Prepare data for charts */
|
163 |
+
var dataDeliveries = [
|
164 |
+
{
|
165 |
+
label : 'Requests',
|
166 |
+
data : requestStats,
|
167 |
+
points: { symbol: "circle" }
|
168 |
+
},
|
169 |
+
{
|
170 |
+
label : 'Drops',
|
171 |
+
data : dropStats,
|
172 |
+
points: { symbol: "square" }
|
173 |
+
},
|
174 |
+
{
|
175 |
+
label : 'Delivered',
|
176 |
+
data : deliveredStats,
|
177 |
+
points: { symbol: "diamond" }
|
178 |
+
}];
|
179 |
+
|
180 |
+
var dataCompliance = [
|
181 |
+
{
|
182 |
+
label : 'Spam reports',
|
183 |
+
data : spamreportStats,
|
184 |
+
points: { symbol: "circle" }
|
185 |
+
},
|
186 |
+
{
|
187 |
+
label : 'Bounces',
|
188 |
+
data : bounceStats,
|
189 |
+
points: { symbol: "square" }
|
190 |
+
},
|
191 |
+
{
|
192 |
+
label : 'Blocked',
|
193 |
+
data : blockStats,
|
194 |
+
points: { symbol: "diamond" }
|
195 |
+
}
|
196 |
+
];
|
197 |
+
|
198 |
+
var dataEngagement = [
|
199 |
+
{
|
200 |
+
label : 'Unsubscribes',
|
201 |
+
data : unsubscribeStats,
|
202 |
+
points: { symbol: "diamond" }
|
203 |
+
},
|
204 |
+
{
|
205 |
+
label : 'Unique Opens',
|
206 |
+
data : uniqueOpenStats,
|
207 |
+
points: { symbol: "triangle" }
|
208 |
+
},
|
209 |
+
{
|
210 |
+
label : 'Opens',
|
211 |
+
data : openStats,
|
212 |
+
points: { symbol: "square" }
|
213 |
+
},
|
214 |
+
{
|
215 |
+
label : 'Clicks',
|
216 |
+
data : clickStats,
|
217 |
+
points: { symbol: "cross" }
|
218 |
+
}
|
219 |
+
];
|
220 |
+
|
221 |
showChart("#deliveries-container", "#deliveries-container-legend", startDate,
|
222 |
endDate, dataDeliveries, ["#328701", "#bcd516", "#fba617"]);
|
223 |
showChart("#compliance-container", "#compliance-container-legend", startDate,
|
view/partials/sendgrid_stats_compliance.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
-
<img src="
|
7 |
<div id="compliance-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="compliance-container-legend" class="sendgrid-statistics-legend"></div>
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
+
<img src="<?php echo plugin_dir_url( __FILE__ ); ?>../images/loader.gif" class="loading" style="position:absolute;" />
|
7 |
<div id="compliance-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="compliance-container-legend" class="sendgrid-statistics-legend"></div>
|
view/partials/sendgrid_stats_deliveries.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
-
<img src="
|
7 |
<div id="deliveries-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="deliveries-container-legend" class="sendgrid-statistics-legend"></div>
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
+
<img src="<?php echo plugin_dir_url( __FILE__ ); ?>../images/loader.gif" class="loading" style="position:absolute;" />
|
7 |
<div id="deliveries-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="deliveries-container-legend" class="sendgrid-statistics-legend"></div>
|
view/partials/sendgrid_stats_engagement.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
-
<img src="
|
7 |
<div id="engagement-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="engagement-container-legend" class="sendgrid-statistics-legend"></div>
|
3 |
<div class="inside">
|
4 |
|
5 |
<div class="sendgrid-container" style="position:relative;">
|
6 |
+
<img src="<?php echo plugin_dir_url( __FILE__ ); ?>../images/loader.gif" class="loading" style="position:absolute;" />
|
7 |
<div id="engagement-container" class="sendgrid-statistics"></div>
|
8 |
</div>
|
9 |
<div id="engagement-container-legend" class="sendgrid-statistics-legend"></div>
|
view/partials/sendgrid_stats_widget.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<div class="sendgrid-filters-container <?php echo (version_compare(get_bloginfo("version"), '3.7.10', '>') ? "wordpress-new" : ""); ?>">
|
2 |
<div class="sendgrid-filters">
|
3 |
<input type="hidden" id="sendgrid-statistics-type" name="sendgrid-statistics-type" value="wordpress" />
|
4 |
<div class="pull-left">
|
@@ -9,14 +9,14 @@
|
|
9 |
<label for="sendgrid-end-date">End date</label>
|
10 |
<input type="text" id="sendgrid-end-date" name="sendgrid_end_date" />
|
11 |
</div>
|
12 |
-
<a href="#" id="sendgrid-apply-filter" data-filter="<?php if (isset($_GET['page']) and
|
13 |
</div>
|
14 |
-
<div class="loading"><img src="
|
15 |
</div>
|
16 |
<br class="clearfix-clear"/>
|
17 |
<div class="sendgrid-container
|
18 |
-
<?php echo ((version_compare(get_bloginfo("version"), '3.7.10', '>') and !isset($_GET['page'])) ? "wordpress-dashboard-new" : ""); ?>
|
19 |
-
<?php echo (version_compare(get_bloginfo("version"), '3.7.10', '>') ? "wordpress-new" : ""); ?>" style="position:relative;">
|
20 |
<div class="widget others" id="deliveries">
|
21 |
<div class="widget-top">
|
22 |
<div class="widget-title"><h4>Deliveries</h4></div>
|
@@ -26,7 +26,7 @@
|
|
26 |
<div class="pull-left">
|
27 |
<span class="square" style="background-color: rgb(50,135,1);"></span><span>Requests</span>
|
28 |
</div>
|
29 |
-
<div id="requests" class="pull-right">0
|
30 |
</div>
|
31 |
<div class="row clearfix">
|
32 |
<div class="pull-left">
|
@@ -102,7 +102,7 @@
|
|
102 |
</div>
|
103 |
<br class="clearfix-clear"/>
|
104 |
|
105 |
-
<?php if (!isset($_GET['page']) or
|
106 |
<a href="index.php?page=sendgrid-statistics" class="more-statistics">See charts</a>
|
107 |
<br class="clearfix-clear"/>
|
108 |
<?php } ?>
|
1 |
+
<div class="sendgrid-filters-container <?php echo ( version_compare( get_bloginfo("version"), '3.7.10', '>' ) ? "wordpress-new" : "" ); ?>">
|
2 |
<div class="sendgrid-filters">
|
3 |
<input type="hidden" id="sendgrid-statistics-type" name="sendgrid-statistics-type" value="wordpress" />
|
4 |
<div class="pull-left">
|
9 |
<label for="sendgrid-end-date">End date</label>
|
10 |
<input type="text" id="sendgrid-end-date" name="sendgrid_end_date" />
|
11 |
</div>
|
12 |
+
<a href="#" id="sendgrid-apply-filter" data-filter="<?php if ( isset( $_GET['page'] ) and "sendgrid-statistics" == sanitize_text_field( $_GET['page'] ) ) { ?>sendgrid-statistics<?php } else { ?>dashboard<?php } ?>" class="button button-primary">Apply</a>
|
13 |
</div>
|
14 |
+
<div class="loading"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>../images/loader.gif" style="width: 15px; height: 15px;" /></div>
|
15 |
</div>
|
16 |
<br class="clearfix-clear"/>
|
17 |
<div class="sendgrid-container
|
18 |
+
<?php echo ( ( version_compare( get_bloginfo( "version" ), '3.7.10', '>' ) and ! isset( $_GET['page'] ) ) ? "wordpress-dashboard-new" : "" ); ?>
|
19 |
+
<?php echo ( version_compare( get_bloginfo( "version" ), '3.7.10', '>' ) ? "wordpress-new" : ""); ?>" style="position:relative;">
|
20 |
<div class="widget others" id="deliveries">
|
21 |
<div class="widget-top">
|
22 |
<div class="widget-title"><h4>Deliveries</h4></div>
|
26 |
<div class="pull-left">
|
27 |
<span class="square" style="background-color: rgb(50,135,1);"></span><span>Requests</span>
|
28 |
</div>
|
29 |
+
<div id="requests" class="pull-right">0</div>
|
30 |
</div>
|
31 |
<div class="row clearfix">
|
32 |
<div class="pull-left">
|
102 |
</div>
|
103 |
<br class="clearfix-clear"/>
|
104 |
|
105 |
+
<?php if ( ! isset ($_GET['page'] ) or "sendgrid-statistics" != sanitize_text_field( $_GET['page'] ) ) { ?>
|
106 |
<a href="index.php?page=sendgrid-statistics" class="more-statistics">See charts</a>
|
107 |
<br class="clearfix-clear"/>
|
108 |
<?php } ?>
|
view/sendgrid_contextual_help.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>
|
2 |
+
Email Delivery. Simplified.
|
3 |
+
</p>
|
4 |
+
<p>
|
5 |
+
SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity
|
6 |
+
of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time
|
7 |
+
analytics along with flexible APIs that make custom integration a breeze.
|
8 |
+
</p>
|
9 |
+
<p>
|
10 |
+
Before to use this plugin, you'll need to create your very own SendGrid account.
|
11 |
+
Go ahead and do so at <a href="http://sendgrid.com/partner/wordpress" target="_blank">http://sendgrid.com/partner/wordpress</a>
|
12 |
+
</p>
|
13 |
+
<p>
|
14 |
+
To have the SendGrid plugin running after you activated it, please go to plugin's
|
15 |
+
settings page and set the SendGrid credentials, and the way your email will be sent through SMTP or API.
|
16 |
+
<br />
|
17 |
+
You can also set default values for the 'Name', 'Sending Address' and the 'Reply Address'
|
18 |
+
in this page, so that you don\'t need to set these headers every time you want to send an email from your
|
19 |
+
application.
|
20 |
+
</p>
|
21 |
+
<p>
|
22 |
+
After you have done these configurations, all your emails sent from your WordPress installation will go through SendGrid.
|
23 |
+
</p>
|
24 |
+
<p>
|
25 |
+
Now let see how simple is to send a text email:
|
26 |
+
<br />
|
27 |
+
<div class="code">
|
28 |
+
<?php wp_mail('to@address.com\', 'Email Subject', 'Email Body'); ?>
|
29 |
+
</div>
|
30 |
+
<br />
|
31 |
+
If you want to use additional headers, here you have a more complex example:
|
32 |
+
<br />
|
33 |
+
<div class="code">
|
34 |
+
$subject = 'test plugin'
|
35 |
+
<br />
|
36 |
+
$message = 'testing wordpress plugin'
|
37 |
+
<br />
|
38 |
+
$to = array('address1@sendgrid.com', 'Address2 <address2@sendgrid.com>', 'address3@sendgrid.com');
|
39 |
+
<br />
|
40 |
+
<br />
|
41 |
+
$headers = array()
|
42 |
+
<br />
|
43 |
+
$headers[] = 'From: Me Myself <me@example.net>';
|
44 |
+
<br />
|
45 |
+
$headers[] = 'Cc: address4@sendgrid.com';
|
46 |
+
<br />
|
47 |
+
$headers[] = 'Bcc: address5@sendgrid.com';
|
48 |
+
<br />
|
49 |
+
<br />
|
50 |
+
$attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
|
51 |
+
<br />
|
52 |
+
<br />
|
53 |
+
add_filter('wp_mail_content_type', 'set_html_content_type');
|
54 |
+
<br />
|
55 |
+
$mail = wp_mail($to, $subject, $message, $headers, $attachments);
|
56 |
+
<br />
|
57 |
+
remove_filter('wp_mail_content_type', 'set_html_content_type');
|
58 |
+
</div>
|
59 |
+
<br />
|
60 |
+
Where:
|
61 |
+
<br />
|
62 |
+
<ul>
|
63 |
+
<li>$to - Array or comma-separated list of email addresses to send message.</li>
|
64 |
+
<li>$subject - Email subject'); ?></li>
|
65 |
+
<li>$message - Message contents'); ?></li>
|
66 |
+
<li>$headers - Array or "\n" separated list of additional headers. Optional.</li>
|
67 |
+
<li>$attachments - Array or "\n"/"," separated list of files to attach. Optional.</li>
|
68 |
+
</ul>
|
69 |
+
The wp_mail function is sending text emails as default. If you want to send an email with HTML content you have
|
70 |
+
to set the content type to 'text/html' running
|
71 |
+
<span class="code">
|
72 |
+
add_filter('wp_mail_content_type', 'set_html_content_type');
|
73 |
+
</span>
|
74 |
+
function before to wp_mail() one.
|
75 |
+
<br />
|
76 |
+
<br />
|
77 |
+
After wp_mail function you need to run the
|
78 |
+
<span class="code">
|
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>
|
view/sendgrid_settings.php
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
-
<
|
2 |
-
|
3 |
-
<div class="wrap">
|
4 |
<a href="http://sendgrid.com" target="_blank">
|
5 |
<img src="<?php echo plugins_url('/images/logo.png', __FILE__) ?>" width="100" alt="" />
|
6 |
</a>
|
7 |
<h2><?php echo _e('SendGrid Options') ?></h2>
|
8 |
-
<?php if (isset($status) and (
|
9 |
<div id="message" class="<?php echo $status ?>">
|
10 |
<p>
|
11 |
<strong><?php echo $message ?></strong>
|
@@ -13,7 +11,7 @@
|
|
13 |
</div>
|
14 |
<?php endif; ?>
|
15 |
<h3><?php echo _e('SendGrid credentials') ?></h3>
|
16 |
-
<form class="form-table" name="sendgrid_form" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
|
17 |
<table class="form-table">
|
18 |
<tbody>
|
19 |
<tr valign="top">
|
@@ -32,8 +30,8 @@
|
|
32 |
<th scope="row"><?php _e("Send Mail with: "); ?></th>
|
33 |
<td>
|
34 |
<select name="sendgrid_api">
|
35 |
-
<option value="api" id="api" <?php echo (
|
36 |
-
<option value="smtp" id="smtp" <?php echo (
|
37 |
</select>
|
38 |
</td>
|
39 |
</tr>
|
@@ -72,7 +70,7 @@
|
|
72 |
</p>
|
73 |
</form>
|
74 |
<br />
|
75 |
-
<?php if ($valid_credentials): ?>
|
76 |
<h2><?php _e('SendGrid Test') ?></h2>
|
77 |
<h3><?php _e('Send a test email with these settings') ?></h3>
|
78 |
<form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
|
1 |
+
<div class="wrap">
|
|
|
|
|
2 |
<a href="http://sendgrid.com" target="_blank">
|
3 |
<img src="<?php echo plugins_url('/images/logo.png', __FILE__) ?>" width="100" alt="" />
|
4 |
</a>
|
5 |
<h2><?php echo _e('SendGrid Options') ?></h2>
|
6 |
+
<?php if ( isset( $status ) and ( 'updated' == $status or 'error' == $status ) ): ?>
|
7 |
<div id="message" class="<?php echo $status ?>">
|
8 |
<p>
|
9 |
<strong><?php echo $message ?></strong>
|
11 |
</div>
|
12 |
<?php endif; ?>
|
13 |
<h3><?php echo _e('SendGrid credentials') ?></h3>
|
14 |
+
<form class="form-table" name="sendgrid_form" method="POST" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI'] ); ?>">
|
15 |
<table class="form-table">
|
16 |
<tbody>
|
17 |
<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>
|
36 |
</td>
|
37 |
</tr>
|
70 |
</p>
|
71 |
</form>
|
72 |
<br />
|
73 |
+
<?php if ( $valid_credentials ): ?>
|
74 |
<h2><?php _e('SendGrid Test') ?></h2>
|
75 |
<h3><?php _e('Send a test email with these settings') ?></h3>
|
76 |
<form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
|
wpsendgrid.php
CHANGED
@@ -3,437 +3,35 @@
|
|
3 |
Plugin Name: SendGrid
|
4 |
Plugin URI: http://wordpress.org/plugins/sendgrid-email-delivery-simplified/
|
5 |
Description: Email Delivery. Simplified. SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time analytics along with flexible APIs that make custom integration a breeze.
|
6 |
-
Version: 1.
|
7 |
Author: SendGrid
|
8 |
Author URI: http://sendgrid.com
|
9 |
License: GPLv2
|
10 |
*/
|
11 |
|
12 |
-
|
13 |
-
require_once plugin_dir_path( __FILE__ ) . '/lib/SendGridStats.php';
|
14 |
-
require_once plugin_dir_path( __FILE__ ) . '/lib/sendgrid-php/SendGrid_loader.php';
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
define('SENDGRID_CATEGORY', 'wp_sendgrid_plugin');
|
19 |
-
define('SENDGRID_PLUGIN_SETTINGS', 'settings_page_sendgrid-settings');
|
20 |
-
define('SENDGRID_PLUGIN_PAGE', 'dashboard_page_sendgrid-statistics');
|
21 |
-
|
22 |
-
if (!function_exists('wp_mail'))
|
23 |
-
{
|
24 |
-
/**
|
25 |
-
* Send mail, similar to PHP's mail
|
26 |
-
*
|
27 |
-
* A true return value does not automatically mean that the user received the
|
28 |
-
* email successfully. It just only means that the method used was able to
|
29 |
-
* process the request without any errors.
|
30 |
-
*
|
31 |
-
* Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
|
32 |
-
* creating a from address like 'Name <email@address.com>' when both are set. If
|
33 |
-
* just 'wp_mail_from' is set, then just the email address will be used with no
|
34 |
-
* name.
|
35 |
-
*
|
36 |
-
* The default content type is 'text/plain' which does not allow using HTML.
|
37 |
-
* However, you can set the content type of the email by using the
|
38 |
-
* 'wp_mail_content_type' filter.
|
39 |
-
*
|
40 |
-
* The default charset is based on the charset used on the blog. The charset can
|
41 |
-
* be set using the 'wp_mail_charset' filter.
|
42 |
-
*
|
43 |
-
* @since 1.2.1
|
44 |
-
* @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
|
45 |
-
* @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
|
46 |
-
* @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
|
47 |
-
* @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
|
48 |
-
* @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
|
49 |
-
*
|
50 |
-
* @param string|array $to Array or comma-separated list of email addresses to send message.
|
51 |
-
* @param string $subject Email subject
|
52 |
-
* @param string $message Message contents
|
53 |
-
* @param string|array $headers Optional. Additional headers.
|
54 |
-
* @param string|array $attachments Optional. Files to attach.
|
55 |
-
* @return bool Whether the email contents were sent successfully.
|
56 |
-
*/
|
57 |
-
function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
58 |
-
{
|
59 |
-
$sendgrid = new SendGrid(get_option('sendgrid_user'), get_option('sendgrid_pwd'));
|
60 |
-
$mail = new SendGrid\Mail();
|
61 |
-
$method = get_option('sendgrid_api');
|
62 |
-
// Compact the input, apply the filters, and extract them back out
|
63 |
-
extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
|
64 |
-
|
65 |
-
// prepare attachments
|
66 |
-
$attached_files = array();
|
67 |
-
if (!empty($attachments))
|
68 |
-
{
|
69 |
-
if (!is_array($attachments))
|
70 |
-
{
|
71 |
-
$pos = strpos(',', $attachments);
|
72 |
-
if ($pos !== false)
|
73 |
-
{
|
74 |
-
$attachments = preg_split('/,\s*/', $attachments);
|
75 |
-
}
|
76 |
-
else
|
77 |
-
{
|
78 |
-
$attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
if (is_array($attachments)) {
|
83 |
-
foreach ($attachments as $attachment) {
|
84 |
-
if (file_exists($attachment)) {
|
85 |
-
$attached_files[] = $attachment;
|
86 |
-
}
|
87 |
-
}
|
88 |
-
}
|
89 |
-
}
|
90 |
-
|
91 |
-
// Headers
|
92 |
-
$cc = array();
|
93 |
-
$bcc = array();
|
94 |
-
if (empty($headers)) {
|
95 |
-
$headers = array();
|
96 |
-
} else {
|
97 |
-
if (!is_array($headers)) {
|
98 |
-
// Explode the headers out, so this function can take both
|
99 |
-
// string headers and an array of headers.
|
100 |
-
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
|
101 |
-
} else {
|
102 |
-
$tempheaders = $headers;
|
103 |
-
}
|
104 |
-
$headers = array();
|
105 |
-
|
106 |
-
// If it's actually got contents
|
107 |
-
if ( !empty( $tempheaders ) ) {
|
108 |
-
// Iterate through the raw headers
|
109 |
-
foreach ( (array) $tempheaders as $header ) {
|
110 |
-
if ( strpos($header, ':') === false ) {
|
111 |
-
if ( false !== stripos( $header, 'boundary=' ) ) {
|
112 |
-
$parts = preg_split('/boundary=/i', trim( $header ) );
|
113 |
-
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
|
114 |
-
}
|
115 |
-
continue;
|
116 |
-
}
|
117 |
-
// Explode them out
|
118 |
-
list( $name, $content ) = explode( ':', trim( $header ), 2 );
|
119 |
-
|
120 |
-
// Cleanup crew
|
121 |
-
$name = trim( $name );
|
122 |
-
$content = trim( $content );
|
123 |
-
|
124 |
-
switch ( strtolower( $name ) ) {
|
125 |
-
// Mainly for legacy -- process a From: header if it's there
|
126 |
-
case 'from':
|
127 |
-
if ( strpos($content, '<' ) !== false ) {
|
128 |
-
// So... making my life hard again?
|
129 |
-
$from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
|
130 |
-
$from_name = str_replace( '"', '', $from_name );
|
131 |
-
$from_name = trim( $from_name );
|
132 |
-
|
133 |
-
$from_email = substr( $content, strpos( $content, '<' ) + 1 );
|
134 |
-
$from_email = str_replace( '>', '', $from_email );
|
135 |
-
$from_email = trim( $from_email );
|
136 |
-
} else {
|
137 |
-
$from_email = trim( $content );
|
138 |
-
}
|
139 |
-
break;
|
140 |
-
case 'content-type':
|
141 |
-
if ( strpos( $content, ';' ) !== false ) {
|
142 |
-
list( $type, $charset ) = explode( ';', $content );
|
143 |
-
$content_type = trim( $type );
|
144 |
-
if ( false !== stripos( $charset, 'charset=' ) ) {
|
145 |
-
$charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
|
146 |
-
} elseif ( false !== stripos( $charset, 'boundary=' ) ) {
|
147 |
-
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
|
148 |
-
$charset = '';
|
149 |
-
}
|
150 |
-
} else {
|
151 |
-
$content_type = trim( $content );
|
152 |
-
}
|
153 |
-
break;
|
154 |
-
case 'cc':
|
155 |
-
$cc = array_merge( (array) $cc, explode( ',', $content ) );
|
156 |
-
foreach ($cc as $key => $recipient)
|
157 |
-
{
|
158 |
-
$cc[$key] = trim($recipient);
|
159 |
-
}
|
160 |
-
break;
|
161 |
-
case 'bcc':
|
162 |
-
$bcc = array_merge( (array) $bcc, explode( ',', $content ) );
|
163 |
-
foreach ($bcc as $key => $recipient)
|
164 |
-
{
|
165 |
-
$bcc[$key] = trim($recipient);
|
166 |
-
}
|
167 |
-
break;
|
168 |
-
case 'reply-to':
|
169 |
-
$replyto = $content;
|
170 |
-
break;
|
171 |
-
default:
|
172 |
-
// Add it to our grand headers array
|
173 |
-
$headers[trim( $name )] = trim( $content );
|
174 |
-
break;
|
175 |
-
}
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
// From email and name
|
181 |
-
// If we don't have a name from the input headers
|
182 |
-
if ( !isset( $from_name ) )
|
183 |
-
$from_name = get_option('sendgrid_from_name');
|
184 |
-
|
185 |
-
/* If we don't have an email from the input headers default to wordpress@$sitename
|
186 |
-
* Some hosts will block outgoing mail from this address if it doesn't exist but
|
187 |
-
* there's no easy alternative. Defaulting to admin_email might appear to be another
|
188 |
-
* option but some hosts may refuse to relay mail from an unknown domain. See
|
189 |
-
* http://trac.wordpress.org/ticket/5007.
|
190 |
-
*/
|
191 |
-
|
192 |
-
if ( !isset( $from_email ) ) {
|
193 |
-
$from_email = trim(get_option('sendgrid_from_email'));
|
194 |
-
if (!$from_email)
|
195 |
-
{
|
196 |
-
// Get the site domain and get rid of www.
|
197 |
-
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
|
198 |
-
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
|
199 |
-
$sitename = substr( $sitename, 4 );
|
200 |
-
}
|
201 |
-
|
202 |
-
$from_email = 'wordpress@' . $sitename;
|
203 |
-
}
|
204 |
-
}
|
205 |
-
|
206 |
-
// Plugin authors can override the potentially troublesome default
|
207 |
-
$from_email = apply_filters( 'wp_mail_from' , $from_email );
|
208 |
-
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
209 |
-
|
210 |
-
// Set destination addresses
|
211 |
-
if ( !is_array( $to ) )
|
212 |
-
$to = explode( ',', $to );
|
213 |
-
|
214 |
-
// Add any CC and BCC recipients
|
215 |
-
if (!empty( $cc ))
|
216 |
-
{
|
217 |
-
foreach ((array) $cc as $key => $recipient)
|
218 |
-
{
|
219 |
-
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
220 |
-
if (preg_match('/(.*)<(.+)>/', $recipient, $matches))
|
221 |
-
{
|
222 |
-
if ( count( $matches ) == 3 )
|
223 |
-
{
|
224 |
-
$cc[$key] = trim($matches[2]);
|
225 |
-
}
|
226 |
-
}
|
227 |
-
}
|
228 |
-
}
|
229 |
-
|
230 |
-
if ( !empty( $bcc ) ) {
|
231 |
-
foreach ( (array) $bcc as $key => $recipient) {
|
232 |
-
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
233 |
-
if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
|
234 |
-
if ( count( $matches ) == 3 )
|
235 |
-
{
|
236 |
-
$bcc[$key] = trim($matches[2]);
|
237 |
-
}
|
238 |
-
}
|
239 |
-
}
|
240 |
-
}
|
241 |
-
|
242 |
-
if (($method == 'api') and (count($cc) or count($bcc)))
|
243 |
-
{
|
244 |
-
foreach ((array) $to as $key => $recipient)
|
245 |
-
{
|
246 |
-
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
247 |
-
if (preg_match( '/(.*)<(.+)>/', $recipient, $matches ) )
|
248 |
-
{
|
249 |
-
if ( count( $matches ) == 3 ) {
|
250 |
-
$to[$key] = trim($matches[2]);
|
251 |
-
}
|
252 |
-
}
|
253 |
-
}
|
254 |
-
}
|
255 |
-
// Set Content-Type and charset
|
256 |
-
// If we don't have a content-type from the input headers
|
257 |
-
if ( !isset( $content_type ) )
|
258 |
-
$content_type = 'text/plain';
|
259 |
-
|
260 |
-
$content_type = apply_filters( 'wp_mail_content_type', $content_type );
|
261 |
-
|
262 |
-
$mail->setTos($to)
|
263 |
-
->setSubject($subject)
|
264 |
-
->setText($message)
|
265 |
-
->setCategory(SENDGRID_CATEGORY)
|
266 |
-
->setFrom($from_email);
|
267 |
-
|
268 |
-
// send HTML content
|
269 |
-
if ($content_type !== 'text/plain')
|
270 |
-
{
|
271 |
-
$mail->setHtml($message);
|
272 |
-
}
|
273 |
-
// set from name
|
274 |
-
if ($from_email)
|
275 |
-
{
|
276 |
-
$mail->setFromName($from_name);
|
277 |
-
}
|
278 |
-
// set from cc
|
279 |
-
if (count($cc))
|
280 |
-
{
|
281 |
-
$mail->setCcs($cc);
|
282 |
-
}
|
283 |
-
// set from bcc
|
284 |
-
if (count($bcc))
|
285 |
-
{
|
286 |
-
$mail->setBccs($bcc);
|
287 |
-
}
|
288 |
-
if (isset($replyto))
|
289 |
-
{
|
290 |
-
$mail->setReplyTo($replyto);
|
291 |
-
}
|
292 |
-
else
|
293 |
-
{
|
294 |
-
$reply_to = trim(get_option('sendgrid_reply_to'));
|
295 |
-
$mail->setReplyTo($reply_to);
|
296 |
-
}
|
297 |
-
// add attachemnts
|
298 |
-
if (count($attached_files))
|
299 |
-
{
|
300 |
-
$mail->setAttachments($attached_files);
|
301 |
-
}
|
302 |
-
|
303 |
-
// Send!
|
304 |
-
try
|
305 |
-
{
|
306 |
-
if ($method == 'api')
|
307 |
-
{
|
308 |
-
return $sendgrid->web->send($mail);
|
309 |
-
}
|
310 |
-
elseif ($method == 'smtp')
|
311 |
-
{
|
312 |
-
if (class_exists('Swift'))
|
313 |
-
{
|
314 |
-
return $sendgrid->smtp->send($mail);
|
315 |
-
}
|
316 |
-
else
|
317 |
-
{
|
318 |
-
return 'Error: Swift Class not loaded. Please activate Swift plugin or use API.';
|
319 |
-
}
|
320 |
-
}
|
321 |
-
}
|
322 |
-
catch (Exception $e)
|
323 |
-
{
|
324 |
-
return $e->getMessage();
|
325 |
-
}
|
326 |
-
|
327 |
-
return false;
|
328 |
-
}
|
329 |
-
}
|
330 |
-
else
|
331 |
-
{
|
332 |
-
/**
|
333 |
-
* wp_mail has been declared by another process or plugin, so you won't be able to use SENDGRID until the problem is solved.
|
334 |
-
*/
|
335 |
-
add_action('admin_notices', 'adminNotices');
|
336 |
|
337 |
/**
|
338 |
-
* Display the notice
|
339 |
*
|
340 |
* return void
|
341 |
*/
|
342 |
-
function
|
343 |
-
{
|
344 |
-
echo '<div class="error"><p>'.__('SendGrid: wp_mail has been declared by another process or plugin, so you won\'t be able to use SendGrid until the conflict is solved.') . '</p></div>';
|
345 |
-
}
|
346 |
-
}
|
347 |
-
|
348 |
-
/**
|
349 |
-
* Add settings link on the plugin page
|
350 |
-
*
|
351 |
-
* @param mixed $links links
|
352 |
-
* @return mixed links
|
353 |
-
*/
|
354 |
-
function sendgrid_settings_link($links)
|
355 |
-
{
|
356 |
-
$settings_link = '<a href="options-general.php?page=sendgrid-settings.php">Settings</a>';
|
357 |
-
array_unshift($links, $settings_link);
|
358 |
-
|
359 |
-
return $links;
|
360 |
-
}
|
361 |
-
add_filter("plugin_action_links_$plugin", 'sendgrid_settings_link' );
|
362 |
-
|
363 |
-
/**
|
364 |
-
* Generates source of contextual help panel.
|
365 |
-
*
|
366 |
-
* @param mixed $contextual_help contextual help
|
367 |
-
* @param integer $screen_id screen id
|
368 |
-
* @param integer $screen screen
|
369 |
-
* @return string
|
370 |
-
*/
|
371 |
-
function showContextualHelp($contextual_help, $screen_id, $screen)
|
372 |
-
{
|
373 |
-
if ($screen_id == SENDGRID_PLUGIN_PAGE or $screen_id == SENDGRID_PLUGIN_SETTINGS)
|
374 |
{
|
375 |
-
|
376 |
-
'<p>' . __("SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity " .
|
377 |
-
"of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time " .
|
378 |
-
"analytics along with flexible APIs that make custom integration a breeze.") . '</p>' .
|
379 |
-
'<p><br />' . __('Before to use this plugin, you\'ll need to create your very own SendGrid account. ' .
|
380 |
-
' Go ahead and do so at <a href="http://sendgrid.com/partner/wordpress" target="_blank">http://sendgrid.com/partner/wordpress</a>') .
|
381 |
-
'</p><p>' . __('To have the SendGrid plugin running after you activated it, please go to plugin\'s ' .
|
382 |
-
'settings page and set the SendGrid credentials, and the way your email will be sent through SMTP or API.') .
|
383 |
-
'<br />' . __('You can also set default values for the \'Name\', \'Sending Address\' and the \'Reply Address\' ' .
|
384 |
-
' in this page, so that you don\'t need to set these headers every time you want to send an email from your ' .
|
385 |
-
'application.') . '</p>' .
|
386 |
-
'<p>' . __('After you have done these configurations, all your emails sent from your WordPress installation will ' .
|
387 |
-
'go through SendGrid.') . '</p><p>' . __('Now let see how simple is to send a text email:') . '<br />' .
|
388 |
-
'<div class="code">' . __('<?php wp_mail(\'to@address.com\', \'Email Subject\', \'Email Body\'); ?>') . '</div><br />' .
|
389 |
-
|
390 |
-
__('If you want to use additional headers, here you have a more complex example:') . '<br />' .
|
391 |
-
|
392 |
-
'<div class="code">$subject = \'test plugin\'<br />' .
|
393 |
-
'$message = \'testing wordpress plugin\'<br />' .
|
394 |
-
'$to = array(\'address1@sendgrid.com\', \'Address2 <address2@sendgrid.com>\', \'address3@sendgrid.com\');<br /><br />' .
|
395 |
-
|
396 |
-
'$headers = array();<br />' .
|
397 |
-
'$headers[] = \'From: Me Myself <me@example.net>\';<br />' .
|
398 |
-
'$headers[] = \'Cc: address4@sendgrid.com\';<br />' .
|
399 |
-
'$headers[] = \'Bcc: address5@sendgrid.com\';<br /><br />' .
|
400 |
-
|
401 |
-
'$attachments = array(\'/tmp/img1.jpg\', \'/tmp/img2.jpg\');<br /><br />' .
|
402 |
-
|
403 |
-
'add_filter(\'wp_mail_content_type\', \'set_html_content_type\');<br />' .
|
404 |
-
'$mail = wp_mail($to, $subject, $message, $headers, $attachments);<br />' .
|
405 |
-
|
406 |
-
'remove_filter(\'wp_mail_content_type\', \'set_html_content_type\');</div><br /><br />' .
|
407 |
-
|
408 |
-
'Where:<br />' .
|
409 |
-
'<ul>' .
|
410 |
-
'<li>$to - ' . __('Array or comma-separated list of email addresses to send message.') . '</li>' .
|
411 |
-
'<li>$subject - ' . __('Email subject') . '</li>' .
|
412 |
-
'<li>$message - ' . __('Message contents') . '</li>' .
|
413 |
-
'<li>$headers - ' . __('Array or "\n" separated list of additional headers. Optional.') . '</li>' .
|
414 |
-
'<li>$attachments - ' . __('Array or "\n"/"," separated list of files to attach. Optional.') . '</li>' .
|
415 |
-
'</ul>' .
|
416 |
-
__('The wp_mail function is sending text emails as default. If you want to send an email with HTML content you have ' .
|
417 |
-
'to set the content type to \'text/html\' running') . ' <span class="code">add_filter(\'wp_mail_content_type\', ' .
|
418 |
-
'\'set_html_content_type\');</span> ' . __('function before to wp_mail() one') . '.<br /><br />' .
|
419 |
-
__('After wp_mail function you need to run the ') . '<span class="code">remove_filter(\'wp_mail_content_type\', ' .
|
420 |
-
'\'set_html_content_type\');</span>' . __(' to remove the \'text/html\' filter to avoid conflicts') .
|
421 |
-
' -- http://core.trac.wordpress.org/ticket/23578';
|
422 |
}
|
|
|
|
|
|
|
|
|
|
|
423 |
|
424 |
-
|
425 |
-
|
426 |
-
add_filter('contextual_help', 'showContextualHelp', 10, 3);
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
/**
|
431 |
-
* Return the content type used to send html emails
|
432 |
-
*
|
433 |
-
* return string Conteny-type needed to send HTML emails
|
434 |
-
*/
|
435 |
-
function set_html_content_type()
|
436 |
-
{
|
437 |
-
return 'text/html';
|
438 |
-
}
|
439 |
}
|
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.0
|
7 |
Author: SendGrid
|
8 |
Author URI: http://sendgrid.com
|
9 |
License: GPLv2
|
10 |
*/
|
11 |
|
12 |
+
$plugin = plugin_basename( __FILE__ );
|
|
|
|
|
13 |
|
14 |
+
if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
|
15 |
+
add_action( 'admin_notices', 'php_version_error' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
/**
|
18 |
+
* Display the notice if PHP version is lower than plugin need
|
19 |
*
|
20 |
* return void
|
21 |
*/
|
22 |
+
function php_version_error()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
{
|
24 |
+
echo '<div class="error"><p>'.__('SendGrid: Plugin require PHP >= 5.3.0.') . '</p></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
+
} else {
|
27 |
+
require_once plugin_dir_path( __FILE__ ) . '/lib/class-sendgrid-tools.php';
|
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 );
|
|
|
34 |
|
35 |
+
// Initialize SendGrid Statistics
|
36 |
+
new Sendgrid_Statistics();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|