Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Email\Outgoing;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -29,14 +29,6 @@ class _SendGrid extends \IPS\Email
|
||||
*/
|
||||
const MAX_EMAILS_PER_GO = 1000; // SendGrid has a hard 1000 recipients per request limit
|
||||
|
||||
/**
|
||||
* @brief If sending a bulk email to more than MAX_EMAILS_PER_GO - does this
|
||||
* class require waiting between cycles? For "standard" classes like
|
||||
* PHP and SMTP, this will be TRUE - and will cause bulk mails to go
|
||||
* to a class. For APIs like SparkPost, this can be FALSE
|
||||
*/
|
||||
const REQUIRES_TIME_BREAK = FALSE;
|
||||
|
||||
/**
|
||||
* @brief API Key
|
||||
*/
|
||||
@@ -86,7 +78,7 @@ class _SendGrid extends \IPS\Email
|
||||
/* Add the recipients */
|
||||
foreach ( array( 'to', 'cc', 'bcc' ) as $type )
|
||||
{
|
||||
if ( is_array( $$type ) )
|
||||
if ( \is_array( $$type ) )
|
||||
{
|
||||
foreach ( $$type as $recipient )
|
||||
{
|
||||
@@ -143,8 +135,8 @@ class _SendGrid extends \IPS\Email
|
||||
/* Add the subject and content */
|
||||
$subject = $this->compileSubject( NULL, $language );
|
||||
$htmlContent = $this->compileContent( 'html', FALSE, $language );
|
||||
$plaintextContent = $this->compileContent( 'plaintext', FALSE, $language );
|
||||
$request['subject'] = $subject;
|
||||
$plaintextContent = preg_replace( '/\*\|(.+?)\|\*/', '*|$1_plain|*', $this->compileContent( 'plaintext', FALSE, $language ) );
|
||||
$request['subject'] = preg_replace( '/\*\|(.+?)\|\*/', '*|$1_plain|*', $subject );
|
||||
$request['content'] = array(
|
||||
array(
|
||||
'type' => 'text/plain',
|
||||
@@ -166,7 +158,8 @@ class _SendGrid extends \IPS\Email
|
||||
foreach ( $substitutions as $k => $v )
|
||||
{
|
||||
$language->parseEmail( $v );
|
||||
$finalSubstitutions["*|{$k}|*"] = $v;
|
||||
$finalSubstitutions["*|{$k}_plain|*"] = $v;
|
||||
$finalSubstitutions["*|{$k}|*"] = htmlspecialchars( $v, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', TRUE );
|
||||
}
|
||||
|
||||
$request['personalizations'][] = array(
|
||||
@@ -177,6 +170,9 @@ class _SendGrid extends \IPS\Email
|
||||
|
||||
/* Add additional headers */
|
||||
$request = $this->_modifyRequestDataWithHeaders( $request, $additionalHeaders );
|
||||
|
||||
/* Log emails sent */
|
||||
$this->_trackStatistics( \count( $addresses ) );
|
||||
|
||||
/* Send */
|
||||
try
|
||||
@@ -202,7 +198,7 @@ class _SendGrid extends \IPS\Email
|
||||
$errorcount = 0;
|
||||
if ( isset( $response['errors'] ) )
|
||||
{
|
||||
$errorcount = count( $response['errors'] );
|
||||
$errorcount = \count( $response['errors'] );
|
||||
\IPS\Db::i()->insert( 'core_mail_error_logs', array(
|
||||
'mlog_date' => time(),
|
||||
'mlog_to' => json_encode( $addresses ),
|
||||
@@ -214,17 +210,20 @@ class _SendGrid extends \IPS\Email
|
||||
'mlog_smtp_log' => NULL
|
||||
) );
|
||||
}
|
||||
return ( count( $recipients ) - $errorcount );
|
||||
|
||||
$successCount = ( \count( $recipients ) - $errorcount );
|
||||
|
||||
/* Update ad impression count */
|
||||
\IPS\core\Advertisement::updateEmailImpressions( $successCount );
|
||||
|
||||
return $successCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a request
|
||||
*
|
||||
* @param array $recipients Array where the keys are the email addresses to send to and the values are an array of variables to replace
|
||||
* @param mixed $fromEmail The email address to send from. If NULL, default setting is used. NOTE: This should always be a site-controlled domin. Some services like Sparkpost require the domain to be validated.
|
||||
* @param mixed $fromName The name the email should appear from. If NULL, default setting is used
|
||||
* @param array $additionalHeaders Additional headers to send. Merge tags can be used like in content.
|
||||
* @param \IPS|Lang $language The language the email content should be in
|
||||
* @return array
|
||||
*/
|
||||
protected function _initRequest( $fromEmail = NULL, $fromName = NULL )
|
||||
@@ -248,7 +247,7 @@ class _SendGrid extends \IPS\Email
|
||||
|
||||
if ( \IPS\Settings::i()->sendgrid_ip_pool )
|
||||
{
|
||||
$request['ip_pool_name'] = (bool) \IPS\Settings::i()->sendgrid_ip_pool;
|
||||
$request['ip_pool_name'] = \IPS\Settings::i()->sendgrid_ip_pool;
|
||||
}
|
||||
|
||||
return $request;
|
||||
@@ -297,7 +296,7 @@ class _SendGrid extends \IPS\Email
|
||||
unset( $additionalHeaders['To'] );
|
||||
unset( $additionalHeaders['CC'] );
|
||||
unset( $additionalHeaders['BCC'] );
|
||||
if ( count( $additionalHeaders ) )
|
||||
if ( \count( $additionalHeaders ) )
|
||||
{
|
||||
$request['headers'] = $additionalHeaders;
|
||||
}
|
||||
@@ -310,7 +309,6 @@ class _SendGrid extends \IPS\Email
|
||||
* Make API call
|
||||
*
|
||||
* @param string $method Method
|
||||
* @param string $apiKey API Key
|
||||
* @param array $args Arguments
|
||||
* @throws \IPS\Email\Outgoing\Exception Indicates an invalid JSON response or HTTP error
|
||||
* @return array|null
|
||||
|
||||
Reference in new issue
Block a user