public function send(SendGrid\Email $email) { $fields = $email->toWebFormat(); $headers = array(); if ("credentials" == $this->method) { $fields['api_user'] = $this->username; $fields['api_key'] = $this->password; } else { $headers = array('Authorization' => 'Bearer ' . $this->apikey); } $files = preg_grep('/files/', array_keys($fields)); foreach ($files as $k => $file) { $fields[$file] = file_get_contents(substr($fields[$file], 1)); } $data = array('body' => $fields); if (count($headers)) { $data['headers'] = $headers; } $response = wp_remote_post(self::URL, $data); if (!is_array($response) or !isset($response['body'])) { return false; } if ("success" == json_decode($response['body'])->message) { return true; } return false; }
/** * Override Email send * * @param SendGrid\Email $email Email object with email info * @param SendGrid $sendgrid Sendgrid object with credentials info * @return array Array of results */ function wp_send(SendGrid\Email $email, $sendgrid) { $form = $email->toWebFormat(); $form['api_user'] = Sendgrid_Tools::get_username(); $form['api_key'] = Sendgrid_Tools::get_password(); $url = $sendgrid->url . $sendgrid->endpoint; $files = preg_grep('/files/', array_keys($form)); if (count($files) > 0) { if (in_array('curl', get_loaded_extensions())) { $response = $sendgrid->postRequest($sendgrid->endpoint, $form); $response = array('body' => $response->raw_body); } else { update_option('sendgrid_curl_option', 'disabled'); foreach ($files as $key => $value) { unset($form[$value]); } $data = array('body' => $form); $response = wp_remote_post($url, $data); } } else { $data = array('body' => $form); $response = wp_remote_post($url, $data); } return $response; }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->api_user; $form['api_key'] = $this->api_key; $response = $this->makeRequest($form); return $response; }
/** * Override Email send * * @param SendGrid\Email $email Email object with email info * @param SendGrid $sendgrid Sendgrid object with credentials info * @return array Array of results */ function wp_send(SendGrid\Email $email, $sendgrid) { $form = $email->toWebFormat(); $form['api_user'] = Sendgrid_Tools::get_username(); $form['api_key'] = Sendgrid_Tools::get_password(); $form = array('body' => $form); $response = wp_remote_post($sendgrid->url, $form); return $response; }
/** * Makes a post request to SendGrid to send an email * @param SendGrid\Email $email Email object built * @throws SendGrid\Exception if the response code is not 200 * @return stdClass SendGrid response object */ public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->apiUser; $form['api_key'] = $this->apiKey; $response = $this->postRequest($this->endpoint, $form); if ($response->code != 200) { throw new SendGrid\Exception($response->raw_body, $response->code); } return $response; }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->username; $form['api_key'] = $this->password; // option to ignore verification of ssl certificate if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) { \Unirest::verifyPeer(false); } $response = \Unirest::post($this->url, array(), $form); return $response->body; }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->api_user; $form['api_key'] = $this->api_key; // option to ignore verification of ssl certificate if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) { \Unirest::verifyPeer(false); } $response = \Unirest::post($this->url, array('User-Agent' => 'sendgrid/' . $this->version . ';php'), $form); return $response->body; }
/** * Makes a post request to SendGrid to send an email * * @param SendGrid\Email $email Email object built * * @throws SendGrid\Exception if the response code is not 200 * @return stdClass SendGrid response object */ public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); // Using username password if ($this->apiUser !== null) { $form['api_user'] = $this->apiUser; $form['api_key'] = $this->apiKey; } $response = $this->postRequest($this->endpoint, $form); if ($response->code != 200 && $this->options['raise_exceptions']) { throw new SendGrid\Exception($response->raw_body, $response->code); } return $response; }
public function testToWebFormatWithFilters() { $email = new \SendGrid\Email(); $email->addFilter('footer', 'text/plain', 'Here is a plain text footer'); $json = $email->toWebFormat(); $xsmtpapi = json_decode($json['x-smtpapi'], TRUE); $this->assertEquals('Here is a plain text footer', $xsmtpapi['filters']['footer']['settings']['text/plain']); }
public function testToWebFormatWithMessageHeaders() { $email = new SendGrid\Email(); $email->addMessageHeader('X-Sent-Using', 'SendGrid-API'); $json = $email->toWebFormat(); $headers = json_decode($json['headers'], TRUE); $this->assertEquals('SendGrid-API', $headers['X-Sent-Using']); }