mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 20:46:03 +03:00
PHP CS Fixer
This commit is contained in:
parent
09eda3df13
commit
8da94ac190
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Connection\Exceptions;
|
||||
|
||||
class GenericHTTPError extends \Exception
|
||||
@ -24,5 +25,3 @@ class GenericHTTPError extends \Exception
|
||||
return $this->httpResponseBody;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Connection\Exceptions;
|
||||
|
||||
class InvalidCredentials extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Connection\Exceptions;
|
||||
|
||||
class MissingEndpoint extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Connection\Exceptions;
|
||||
|
||||
class MissingRequiredParameters extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Connection\Exceptions;
|
||||
|
||||
class NoDomainsConfigured extends \Exception
|
||||
|
@ -20,7 +20,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class RestClient
|
||||
{
|
||||
/**
|
||||
* Your API key
|
||||
* Your API key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
@ -37,14 +37,14 @@ class RestClient
|
||||
protected $apiHost;
|
||||
|
||||
/**
|
||||
* The version of the API to use
|
||||
* The version of the API to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $apiVersion = 'v2';
|
||||
|
||||
/**
|
||||
* If we should use SSL or not
|
||||
* If we should use SSL or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
@ -275,9 +275,7 @@ class RestClient
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HttpClient
|
||||
*/
|
||||
protected function getHttpClient()
|
||||
@ -299,7 +297,6 @@ class RestClient
|
||||
return $this->generateEndpoint($this->apiHost, $this->apiVersion, $this->sslEnabled).$uri;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $apiEndpoint
|
||||
* @param string $apiVersion
|
||||
@ -325,7 +322,7 @@ class RestClient
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $sslEnabled
|
||||
* @param bool $sslEnabled
|
||||
*
|
||||
* @return RestClient
|
||||
*/
|
||||
|
@ -1,17 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Mailgun\Constants;
|
||||
|
||||
|
||||
class Api
|
||||
{
|
||||
const API_USER = "api";
|
||||
const SDK_VERSION = "1.7";
|
||||
const SDK_USER_AGENT = "mailgun-sdk-php";
|
||||
const API_USER = 'api';
|
||||
const SDK_VERSION = '1.7';
|
||||
const SDK_USER_AGENT = 'mailgun-sdk-php';
|
||||
const RECIPIENT_COUNT_LIMIT = 1000;
|
||||
const CAMPAIGN_ID_LIMIT = 3;
|
||||
const TAG_LIMIT = 3;
|
||||
const DEFAULT_TIME_ZONE = "UTC";
|
||||
const DEFAULT_TIME_ZONE = 'UTC';
|
||||
}
|
||||
|
@ -1,22 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Mailgun\Constants;
|
||||
|
||||
|
||||
class ExceptionMessages
|
||||
{
|
||||
const EXCEPTION_INVALID_CREDENTIALS = "Your credentials are incorrect.";
|
||||
const EXCEPTION_GENERIC_HTTP_ERROR = "An HTTP Error has occurred! Check your network connection and try again.";
|
||||
const EXCEPTION_MISSING_REQUIRED_PARAMETERS = "The parameters passed to the API were invalid. Check your inputs!";
|
||||
const EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS = "The parameters passed to the API were invalid. Check your inputs!";
|
||||
const EXCEPTION_INVALID_CREDENTIALS = 'Your credentials are incorrect.';
|
||||
const EXCEPTION_GENERIC_HTTP_ERROR = 'An HTTP Error has occurred! Check your network connection and try again.';
|
||||
const EXCEPTION_MISSING_REQUIRED_PARAMETERS = 'The parameters passed to the API were invalid. Check your inputs!';
|
||||
const EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS = 'The parameters passed to the API were invalid. Check your inputs!';
|
||||
const EXCEPTION_MISSING_ENDPOINT = "The endpoint you've tried to access does not exist. Check your URL.";
|
||||
const TOO_MANY_RECIPIENTS = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled.";
|
||||
const INVALID_PARAMETER_NON_ARRAY = "The parameter you've passed in position 2 must be an array.";
|
||||
const INVALID_PARAMETER_ATTACHMENT = "Attachments must be passed with an \"@\" preceding the file path. Web resources not supported.";
|
||||
const INVALID_PARAMETER_INLINE = "Inline images must be passed with an \"@\" preceding the file path. Web resources not supported.";
|
||||
const INVALID_PARAMETER_ATTACHMENT = 'Attachments must be passed with an "@" preceding the file path. Web resources not supported.';
|
||||
const INVALID_PARAMETER_INLINE = 'Inline images must be passed with an "@" preceding the file path. Web resources not supported.';
|
||||
const TOO_MANY_PARAMETERS_CAMPAIGNS = "You've exceeded the maximum (3) campaigns for a single message.";
|
||||
const TOO_MANY_PARAMETERS_TAGS = "You've exceeded the maximum (3) tags for a single message.";
|
||||
const TOO_MANY_PARAMETERS_RECIPIENT = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled.";
|
||||
}
|
||||
|
@ -2,10 +2,6 @@
|
||||
|
||||
namespace Mailgun\Lists;
|
||||
|
||||
use Mailgun\Messages\Exceptions\InvalidParameter;
|
||||
use Mailgun\Messages\Exceptions\TooManyParameters;
|
||||
use Mailgun\Messages\Expcetions\InvalidParameterType;
|
||||
|
||||
/**
|
||||
* This class is used for creating a unique hash for
|
||||
* mailing list subscription double-opt in requests.
|
||||
@ -14,11 +10,11 @@ use Mailgun\Messages\Expcetions\InvalidParameterType;
|
||||
*/
|
||||
class OptInHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $mailingList
|
||||
* @param string $secretAppId
|
||||
* @param string $recipientAddress
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateHash($mailingList, $secretAppId, $recipientAddress)
|
||||
@ -26,7 +22,7 @@ class OptInHandler
|
||||
$innerPayload = array('r' => $recipientAddress, 'l' => $mailingList);
|
||||
$encodedInnerPayload = base64_encode(json_encode($innerPayload));
|
||||
|
||||
$innerHash = hash_hmac("sha1", $encodedInnerPayload, $secretAppId);
|
||||
$innerHash = hash_hmac('sha1', $encodedInnerPayload, $secretAppId);
|
||||
$outerPayload = array('h' => $innerHash, 'p' => $encodedInnerPayload);
|
||||
|
||||
return urlencode(base64_encode(json_encode($outerPayload)));
|
||||
@ -35,6 +31,7 @@ class OptInHandler
|
||||
/**
|
||||
* @param string $secretAppId
|
||||
* @param string $uniqueHash
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function validateHash($secretAppId, $uniqueHash)
|
||||
@ -45,7 +42,7 @@ class OptInHandler
|
||||
$innerPayload = $decodedOuterPayload['p'];
|
||||
|
||||
$decodedInnerPayload = json_decode(base64_decode($innerPayload), true);
|
||||
$computedInnerHash = hash_hmac("sha1", $innerPayload, $secretAppId);
|
||||
$computedInnerHash = hash_hmac('sha1', $innerPayload, $secretAppId);
|
||||
|
||||
if ($computedInnerHash == $decodedHash) {
|
||||
return array('recipientAddress' => $decodedInnerPayload['r'], 'mailingList' => $decodedInnerPayload['l']);
|
||||
|
@ -18,7 +18,6 @@ use Mailgun\Messages\MessageBuilder;
|
||||
*/
|
||||
class Mailgun
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RestClient
|
||||
*/
|
||||
@ -51,26 +50,26 @@ class Mailgun
|
||||
* @param string $workingDomain
|
||||
* @param array $postData
|
||||
* @param array $postFiles
|
||||
*
|
||||
* @return \stdClass
|
||||
*
|
||||
* @throws Exceptions\MissingRequiredMIMEParameters
|
||||
*/
|
||||
public function sendMessage($workingDomain, $postData, $postFiles = array())
|
||||
{
|
||||
if (is_array($postFiles)) {
|
||||
return $this->post("$workingDomain/messages", $postData, $postFiles);
|
||||
}
|
||||
else if(is_string($postFiles)) {
|
||||
|
||||
$tempFile = tempnam(sys_get_temp_dir(), "MG_TMP_MIME");
|
||||
$fileHandle = fopen($tempFile, "w");
|
||||
} elseif (is_string($postFiles)) {
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'MG_TMP_MIME');
|
||||
$fileHandle = fopen($tempFile, 'w');
|
||||
fwrite($fileHandle, $postFiles);
|
||||
|
||||
$result = $this->post("$workingDomain/messages.mime", $postData, array("message" => $tempFile));
|
||||
$result = $this->post("$workingDomain/messages.mime", $postData, array('message' => $tempFile));
|
||||
fclose($fileHandle);
|
||||
unlink($tempFile);
|
||||
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw new Exceptions\MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
}
|
||||
}
|
||||
@ -86,6 +85,7 @@ class Mailgun
|
||||
* You should reject the request with status code 403 Forbidden.
|
||||
*
|
||||
* @param array|null $postData
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyWebhookSignature($postData = null)
|
||||
@ -96,14 +96,13 @@ class Mailgun
|
||||
if (!isset($postData['timestamp']) || !isset($postData['token']) || !isset($postData['signature'])) {
|
||||
return false;
|
||||
}
|
||||
$hmac = hash_hmac('sha256', "{$postData["timestamp"]}{$postData["token"]}", $this->apiKey);
|
||||
$hmac = hash_hmac('sha256', "{$postData['timestamp']}{$postData['token']}", $this->apiKey);
|
||||
$sig = $postData['signature'];
|
||||
if (function_exists('hash_equals')) {
|
||||
// hash_equals is constant time, but will not be introduced until PHP 5.6
|
||||
return hash_equals($hmac, $sig);
|
||||
}
|
||||
else {
|
||||
return ($hmac === $sig);
|
||||
} else {
|
||||
return $hmac === $sig;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +110,7 @@ class Mailgun
|
||||
* @param string $endpointUrl
|
||||
* @param array $postData
|
||||
* @param array $files
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function post($endpointUrl, $postData = array(), $files = array())
|
||||
@ -121,6 +121,7 @@ class Mailgun
|
||||
/**
|
||||
* @param string $endpointUrl
|
||||
* @param array $queryString
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get($endpointUrl, $queryString = array())
|
||||
@ -130,6 +131,7 @@ class Mailgun
|
||||
|
||||
/**
|
||||
* @param string $endpointUrl
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function delete($endpointUrl)
|
||||
@ -140,6 +142,7 @@ class Mailgun
|
||||
/**
|
||||
* @param string $endpointUrl
|
||||
* @param array $putData
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function put($endpointUrl, $putData)
|
||||
@ -160,7 +163,7 @@ class Mailgun
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $sslEnabled
|
||||
* @param bool $sslEnabled
|
||||
*
|
||||
* @return Mailgun
|
||||
*/
|
||||
@ -190,6 +193,7 @@ class Mailgun
|
||||
/**
|
||||
* @param string $workingDomain
|
||||
* @param bool $autoSend
|
||||
*
|
||||
* @return BatchMessage
|
||||
*/
|
||||
public function BatchMessage($workingDomain, $autoSend = true)
|
||||
|
@ -15,14 +15,13 @@ use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
||||
*/
|
||||
class BatchMessage extends MessageBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $batchRecipientAttributes;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
private $autoSend;
|
||||
|
||||
@ -49,7 +48,7 @@ class BatchMessage extends MessageBuilder
|
||||
/**
|
||||
* @param \Mailgun\Connection\RestClient $restClient
|
||||
* @param string $workingDomain
|
||||
* @param boolean $autoSend
|
||||
* @param bool $autoSend
|
||||
*/
|
||||
public function __construct($restClient, $workingDomain, $autoSend)
|
||||
{
|
||||
@ -57,13 +56,14 @@ class BatchMessage extends MessageBuilder
|
||||
$this->autoSend = $autoSend;
|
||||
$this->restClient = $restClient;
|
||||
$this->workingDomain = $workingDomain;
|
||||
$this->endpointUrl = $workingDomain . "/messages";
|
||||
$this->endpointUrl = $workingDomain.'/messages';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $headerName
|
||||
* @param string $address
|
||||
* @param array $variables
|
||||
*
|
||||
* @throws MissingRequiredMIMEParameters
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
@ -82,17 +82,15 @@ class BatchMessage extends MessageBuilder
|
||||
|
||||
if (isset($this->message[$headerName])) {
|
||||
array_push($this->message[$headerName], $compiledAddress);
|
||||
}
|
||||
elseif($headerName == "h:reply-to") {
|
||||
} elseif ($headerName == 'h:reply-to') {
|
||||
$this->message[$headerName] = $compiledAddress;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->message[$headerName] = array($compiledAddress);
|
||||
}
|
||||
|
||||
if (array_key_exists($headerName, $this->counters['recipients'])) {
|
||||
$this->counters['recipients'][$headerName] += 1;
|
||||
if(!array_key_exists("id", $variables)) {
|
||||
if (!array_key_exists('id', $variables)) {
|
||||
$variables['id'] = $this->counters['recipients'][$headerName];
|
||||
}
|
||||
}
|
||||
@ -102,6 +100,7 @@ class BatchMessage extends MessageBuilder
|
||||
/**
|
||||
* @param array $message
|
||||
* @param array $files
|
||||
*
|
||||
* @throws MissingRequiredMIMEParameters
|
||||
*/
|
||||
public function sendMessage($message = array(), $files = array())
|
||||
@ -110,26 +109,22 @@ class BatchMessage extends MessageBuilder
|
||||
$message = $this->message;
|
||||
$files = $this->files;
|
||||
}
|
||||
if(!array_key_exists("from", $message)) {
|
||||
if (!array_key_exists('from', $message)) {
|
||||
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
}
|
||||
elseif(!array_key_exists("to", $message)) {
|
||||
} elseif (!array_key_exists('to', $message)) {
|
||||
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
}
|
||||
elseif(!array_key_exists("subject", $message)) {
|
||||
} elseif (!array_key_exists('subject', $message)) {
|
||||
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
}
|
||||
elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))) {
|
||||
} elseif ((!array_key_exists('text', $message) && !array_key_exists('html', $message))) {
|
||||
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
}
|
||||
else{
|
||||
$message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
||||
} else {
|
||||
$message['recipient-variables'] = json_encode($this->batchRecipientAttributes);
|
||||
$response = $this->restClient->post($this->endpointUrl, $message, $files);
|
||||
$this->batchRecipientAttributes = array();
|
||||
$this->counters['recipients']['to'] = 0;
|
||||
$this->counters['recipients']['cc'] = 0;
|
||||
$this->counters['recipients']['bcc'] = 0;
|
||||
unset($this->message["to"]);
|
||||
unset($this->message['to']);
|
||||
array_push($this->messageIds, $response->http_response_body->id);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Messages\Exceptions;
|
||||
|
||||
class InvalidParameter extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Messages\Exceptions;
|
||||
|
||||
class InvalidParameterType extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Messages\Exceptions;
|
||||
|
||||
class MissingRequiredMIMEParameters extends \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Mailgun\Messages\Exceptions;
|
||||
|
||||
class TooManyParameters extends \Exception
|
||||
|
@ -39,20 +39,21 @@ class MessageBuilder
|
||||
'recipients' => array(
|
||||
'to' => 0,
|
||||
'cc' => 0,
|
||||
'bcc' => 0
|
||||
'bcc' => 0,
|
||||
),
|
||||
'attributes' => array(
|
||||
'attachment' => 0,
|
||||
'campaign_id' => 0,
|
||||
'custom_option' => 0,
|
||||
'tag' => 0
|
||||
)
|
||||
'tag' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function safeGet($params, $key, $default)
|
||||
@ -66,23 +67,25 @@ class MessageBuilder
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected function getFullName($params)
|
||||
{
|
||||
if (array_key_exists("first", $params)) {
|
||||
$first = $this->safeGet($params, "first", "");
|
||||
$last = $this->safeGet($params, "last", "");
|
||||
if (array_key_exists('first', $params)) {
|
||||
$first = $this->safeGet($params, 'first', '');
|
||||
$last = $this->safeGet($params, 'last', '');
|
||||
|
||||
return trim("$first $last");
|
||||
}
|
||||
|
||||
return $this->safeGet($params, "full_name", "");
|
||||
return $this->safeGet($params, 'full_name', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array $variables
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function parseAddress($address, $variables)
|
||||
@ -109,7 +112,7 @@ class MessageBuilder
|
||||
|
||||
if (isset($this->message[$headerName])) {
|
||||
array_push($this->message[$headerName], $compiledAddress);
|
||||
} elseif ($headerName == "h:reply-to") {
|
||||
} elseif ($headerName == 'h:reply-to') {
|
||||
$this->message[$headerName] = $compiledAddress;
|
||||
} else {
|
||||
$this->message[$headerName] = array($compiledAddress);
|
||||
@ -122,7 +125,9 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array|null $variables
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
public function addToRecipient($address, $variables = null)
|
||||
@ -130,7 +135,7 @@ class MessageBuilder
|
||||
if ($this->counters['recipients']['to'] > Api::RECIPIENT_COUNT_LIMIT) {
|
||||
throw new TooManyParameters(ExceptionMessages::TOO_MANY_PARAMETERS_RECIPIENT);
|
||||
}
|
||||
$this->addRecipient("to", $address, $variables);
|
||||
$this->addRecipient('to', $address, $variables);
|
||||
|
||||
return end($this->message['to']);
|
||||
}
|
||||
@ -138,7 +143,9 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array|null $variables
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
public function addCcRecipient($address, $variables = null)
|
||||
@ -146,7 +153,7 @@ class MessageBuilder
|
||||
if ($this->counters['recipients']['cc'] > Api::RECIPIENT_COUNT_LIMIT) {
|
||||
throw new TooManyParameters(ExceptionMessages::TOO_MANY_PARAMETERS_RECIPIENT);
|
||||
}
|
||||
$this->addRecipient("cc", $address, $variables);
|
||||
$this->addRecipient('cc', $address, $variables);
|
||||
|
||||
return end($this->message['cc']);
|
||||
}
|
||||
@ -154,7 +161,9 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array|null $variables
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
public function addBccRecipient($address, $variables = null)
|
||||
@ -162,7 +171,7 @@ class MessageBuilder
|
||||
if ($this->counters['recipients']['bcc'] > Api::RECIPIENT_COUNT_LIMIT) {
|
||||
throw new TooManyParameters(ExceptionMessages::TOO_MANY_PARAMETERS_RECIPIENT);
|
||||
}
|
||||
$this->addRecipient("bcc", $address, $variables);
|
||||
$this->addRecipient('bcc', $address, $variables);
|
||||
|
||||
return end($this->message['bcc']);
|
||||
}
|
||||
@ -170,11 +179,12 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array|null $variables
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setFromAddress($address, $variables = null)
|
||||
{
|
||||
$this->addRecipient("from", $address, $variables);
|
||||
$this->addRecipient('from', $address, $variables);
|
||||
|
||||
return $this->message['from'];
|
||||
}
|
||||
@ -182,23 +192,25 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $address
|
||||
* @param array|null $variables
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setReplyToAddress($address, $variables = null)
|
||||
{
|
||||
$this->addRecipient("h:reply-to", $address, $variables);
|
||||
$this->addRecipient('h:reply-to', $address, $variables);
|
||||
|
||||
return $this->message['h:reply-to'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setSubject($subject = "")
|
||||
public function setSubject($subject = '')
|
||||
{
|
||||
if ($subject == null || $subject == "") {
|
||||
$subject = " ";
|
||||
if ($subject == null || $subject == '') {
|
||||
$subject = ' ';
|
||||
}
|
||||
$this->message['subject'] = $subject;
|
||||
|
||||
@ -208,12 +220,13 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $headerName
|
||||
* @param mixed $headerData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addCustomHeader($headerName, $headerData)
|
||||
{
|
||||
if (!preg_match("/^h:/i", $headerName)) {
|
||||
$headerName = "h:" . $headerName;
|
||||
if (!preg_match('/^h:/i', $headerName)) {
|
||||
$headerName = 'h:'.$headerName;
|
||||
}
|
||||
$this->message[$headerName] = array($headerData);
|
||||
|
||||
@ -222,12 +235,13 @@ class MessageBuilder
|
||||
|
||||
/**
|
||||
* @param string $textBody
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setTextBody($textBody)
|
||||
{
|
||||
if ($textBody == null || $textBody == "") {
|
||||
$textBody = " ";
|
||||
if ($textBody == null || $textBody == '') {
|
||||
$textBody = ' ';
|
||||
}
|
||||
$this->message['text'] = $textBody;
|
||||
|
||||
@ -236,12 +250,13 @@ class MessageBuilder
|
||||
|
||||
/**
|
||||
* @param string $htmlBody
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setHtmlBody($htmlBody)
|
||||
{
|
||||
if ($htmlBody == null || $htmlBody == "") {
|
||||
$htmlBody = " ";
|
||||
if ($htmlBody == null || $htmlBody == '') {
|
||||
$htmlBody = ' ';
|
||||
}
|
||||
$this->message['html'] = $htmlBody;
|
||||
|
||||
@ -251,22 +266,23 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $attachmentPath
|
||||
* @param string|null $attachmentName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function addAttachment($attachmentPath, $attachmentName = null)
|
||||
{
|
||||
if (isset($this->files["attachment"])) {
|
||||
if (isset($this->files['attachment'])) {
|
||||
$attachment = array(
|
||||
'filePath' => $attachmentPath,
|
||||
'remoteName' => $attachmentName
|
||||
'remoteName' => $attachmentName,
|
||||
);
|
||||
array_push($this->files["attachment"], $attachment);
|
||||
array_push($this->files['attachment'], $attachment);
|
||||
} else {
|
||||
$this->files["attachment"] = array(
|
||||
$this->files['attachment'] = array(
|
||||
array(
|
||||
'filePath' => $attachmentPath,
|
||||
'remoteName' => $attachmentName
|
||||
)
|
||||
'remoteName' => $attachmentName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -278,6 +294,7 @@ class MessageBuilder
|
||||
* @param string|null $inlineImageName
|
||||
*
|
||||
* @return bool|true
|
||||
*
|
||||
* @throws InvalidParameter
|
||||
*/
|
||||
public function addInlineImage($inlineImagePath, $inlineImageName = null)
|
||||
@ -286,15 +303,15 @@ class MessageBuilder
|
||||
if (isset($this->files['inline'])) {
|
||||
$inlineAttachment = array(
|
||||
'filePath' => $inlineImagePath,
|
||||
'remoteName' => $inlineImageName
|
||||
'remoteName' => $inlineImageName,
|
||||
);
|
||||
array_push($this->files['inline'], $inlineAttachment);
|
||||
} else {
|
||||
$this->files['inline'] = array(
|
||||
array(
|
||||
'filePath' => $inlineImagePath,
|
||||
'remoteName' => $inlineImageName
|
||||
)
|
||||
'remoteName' => $inlineImageName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -305,15 +322,16 @@ class MessageBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $testMode
|
||||
* @param bool $testMode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setTestMode($testMode)
|
||||
{
|
||||
if (filter_var($testMode, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$testMode = "yes";
|
||||
$testMode = 'yes';
|
||||
} else {
|
||||
$testMode = "no";
|
||||
$testMode = 'no';
|
||||
}
|
||||
$this->message['o:testmode'] = $testMode;
|
||||
|
||||
@ -322,7 +340,9 @@ class MessageBuilder
|
||||
|
||||
/**
|
||||
* @param string|int $campaignId
|
||||
*
|
||||
* @return string|int
|
||||
*
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
public function addCampaignId($campaignId)
|
||||
@ -343,6 +363,7 @@ class MessageBuilder
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
*
|
||||
* @throws TooManyParameters
|
||||
*/
|
||||
public function addTag($tag)
|
||||
@ -362,31 +383,33 @@ class MessageBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $enabled
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setDkim($enabled)
|
||||
{
|
||||
if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$enabled = "yes";
|
||||
$enabled = 'yes';
|
||||
} else {
|
||||
$enabled = "no";
|
||||
$enabled = 'no';
|
||||
}
|
||||
$this->message["o:dkim"] = $enabled;
|
||||
$this->message['o:dkim'] = $enabled;
|
||||
|
||||
return $this->message["o:dkim"];
|
||||
return $this->message['o:dkim'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $enabled
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setOpenTracking($enabled)
|
||||
{
|
||||
if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$enabled = "yes";
|
||||
$enabled = 'yes';
|
||||
} else {
|
||||
$enabled = "no";
|
||||
$enabled = 'no';
|
||||
}
|
||||
$this->message['o:tracking-opens'] = $enabled;
|
||||
|
||||
@ -394,17 +417,18 @@ class MessageBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $enabled
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setClickTracking($enabled)
|
||||
{
|
||||
if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$enabled = "yes";
|
||||
} elseif ($enabled == "html") {
|
||||
$enabled = "html";
|
||||
$enabled = 'yes';
|
||||
} elseif ($enabled == 'html') {
|
||||
$enabled = 'html';
|
||||
} else {
|
||||
$enabled = "no";
|
||||
$enabled = 'no';
|
||||
}
|
||||
$this->message['o:tracking-clicks'] = $enabled;
|
||||
|
||||
@ -414,6 +438,7 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $timeDate
|
||||
* @param string|null $timeZone
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setDeliveryTime($timeDate, $timeZone = null)
|
||||
@ -443,6 +468,7 @@ class MessageBuilder
|
||||
/**
|
||||
* @param string $parameterName
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addCustomParameter($parameterName, $data)
|
||||
|
Loading…
Reference in New Issue
Block a user