added the option to set headers in the email helper class

This commit is contained in:
Llewellyn van der Merwe 2018-06-21 16:25:49 +02:00
parent 0c7d7265dd
commit 2b3acf5368
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
5 changed files with 71 additions and 19 deletions

View File

@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 15th June, 2018 + *Last Build*: 21st June, 2018
+ *Version*: 2.8.0 + *Version*: 2.8.0
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **185735** + *Line count*: **185761**
+ *Field count*: **1054** + *Field count*: **1054**
+ *File count*: **1236** + *File count*: **1236**
+ *Folder count*: **197** + *Folder count*: **197**

View File

@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 15th June, 2018 + *Last Build*: 21st June, 2018
+ *Version*: 2.8.0 + *Version*: 2.8.0
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **185735** + *Line count*: **185761**
+ *Field count*: **1054** + *Field count*: **1054**
+ *File count*: **1236** + *File count*: **1236**
+ *Folder count*: **197** + *Folder count*: **197**

View File

@ -45,6 +45,13 @@ abstract class ###Component###Email
*/ */
public static $mailer = null; public static $mailer = null;
/**
* Custom Headers
*
* @var array
*/
protected static $header = array();
/** /**
* Get a configuration object * Get a configuration object
* *
@ -58,7 +65,7 @@ abstract class ###Component###Email
return self::$config; return self::$config;
} }
/** /**
* Get a mailer object. * Get a mailer object.
* *
@ -164,6 +171,17 @@ abstract class ###Component###Email
return $mail; return $mail;
} }
/**
* Set a Mail custom header.
*
* @return void
*/
public static function setHeader($target, $value)
{
// set the header
self::$header[$target] = $value;
}
/** /**
* Send an email * Send an email
* *
@ -172,7 +190,6 @@ abstract class ###Component###Email
*/ */
public static function send($recipient, $subject, $body, $textonly, $mode = 0, $bounce_email = null, $idsession = null, $mailreply = null, $replyname = null , $mailfrom = null, $fromname = null, $cc = null, $bcc = null, $attachment = null, $embeded = null , $embeds = null) public static function send($recipient, $subject, $body, $textonly, $mode = 0, $bounce_email = null, $idsession = null, $mailreply = null, $replyname = null , $mailfrom = null, $fromname = null, $cc = null, $bcc = null, $attachment = null, $embeded = null , $embeds = null)
{ {
// Get a JMail instance // Get a JMail instance
$mail = self::getMailer(); $mail = self::getMailer();
@ -199,7 +216,16 @@ abstract class ###Component###Email
{ {
$mail->addCustomHeader('X-VDMmethodID:'.$idsession); $mail->addCustomHeader('X-VDMmethodID:'.$idsession);
} }
// set headers if found
if (isset(self::$header) && is_array(self::$header) && count((array)self::$header) > 0)
{
foreach (self::$header as $_target => $_value)
{
$mail->addCustomHeader($_target.':'.$_value);
}
}
// set the subject & Body // set the subject & Body
$mail->setSubject($subject); $mail->setSubject($subject);
$mail->setBody($body); $mail->setBody($body);
@ -243,7 +269,7 @@ abstract class ###Component###Email
$mail->ClearReplyTos(); $mail->ClearReplyTos();
$mail->addReplyTo($mailreply, $replyname); $mail->addReplyTo($mailreply, $replyname);
} }
// check if we can add the DKIM to email // check if we can add the DKIM to email
if ($conf->get('enable_dkim')) if ($conf->get('enable_dkim'))
{ {
@ -261,20 +287,20 @@ abstract class ###Component###Email
$mail->DKIM_private = $tmp; $mail->DKIM_private = $tmp;
} }
} }
$sendmail = $mail->Send(); $sendmail = $mail->Send();
if ($conf->get('enable_dkim') && !empty($conf->get('dkim_domain')) && !empty($conf->get('dkim_selector')) && !empty($conf->get('dkim_private')) && !empty($conf->get('dkim_public'))) if ($conf->get('enable_dkim') && !empty($conf->get('dkim_domain')) && !empty($conf->get('dkim_selector')) && !empty($conf->get('dkim_private')) && !empty($conf->get('dkim_public')))
{ {
@unlink($tmp); @unlink($tmp);
} }
if (method_exists('###Component###Helper','storeMessage')) if (method_exists('###Component###Helper','storeMessage'))
{ {
// store the massage if the method is set // store the massage if the method is set
###Component###Helper::storeMessage($sendmail, $recipient, $subject, $body, $textonly, $mode, 'email'); ###Component###Helper::storeMessage($sendmail, $recipient, $subject, $body, $textonly, $mode, 'email');
} }
return $sendmail; return $sendmail;
} }

View File

@ -28,6 +28,13 @@ abstract class ComponentbuilderEmail
*/ */
public static $mailer = null; public static $mailer = null;
/**
* Custom Headers
*
* @var array
*/
protected static $header = array();
/** /**
* Get a configuration object * Get a configuration object
* *
@ -41,7 +48,7 @@ abstract class ComponentbuilderEmail
return self::$config; return self::$config;
} }
/** /**
* Get a mailer object. * Get a mailer object.
* *
@ -147,6 +154,17 @@ abstract class ComponentbuilderEmail
return $mail; return $mail;
} }
/**
* Set a Mail custom header.
*
* @return void
*/
public static function setHeader($target, $value)
{
// set the header
self::$header[$target] = $value;
}
/** /**
* Send an email * Send an email
* *
@ -155,7 +173,6 @@ abstract class ComponentbuilderEmail
*/ */
public static function send($recipient, $subject, $body, $textonly, $mode = 0, $bounce_email = null, $idsession = null, $mailreply = null, $replyname = null , $mailfrom = null, $fromname = null, $cc = null, $bcc = null, $attachment = null, $embeded = null , $embeds = null) public static function send($recipient, $subject, $body, $textonly, $mode = 0, $bounce_email = null, $idsession = null, $mailreply = null, $replyname = null , $mailfrom = null, $fromname = null, $cc = null, $bcc = null, $attachment = null, $embeded = null , $embeds = null)
{ {
// Get a JMail instance // Get a JMail instance
$mail = self::getMailer(); $mail = self::getMailer();
@ -182,7 +199,16 @@ abstract class ComponentbuilderEmail
{ {
$mail->addCustomHeader('X-VDMmethodID:'.$idsession); $mail->addCustomHeader('X-VDMmethodID:'.$idsession);
} }
// set headers if found
if (isset(self::$header) && is_array(self::$header) && count((array)self::$header) > 0)
{
foreach (self::$header as $_target => $_value)
{
$mail->addCustomHeader($_target.':'.$_value);
}
}
// set the subject & Body // set the subject & Body
$mail->setSubject($subject); $mail->setSubject($subject);
$mail->setBody($body); $mail->setBody($body);
@ -226,7 +252,7 @@ abstract class ComponentbuilderEmail
$mail->ClearReplyTos(); $mail->ClearReplyTos();
$mail->addReplyTo($mailreply, $replyname); $mail->addReplyTo($mailreply, $replyname);
} }
// check if we can add the DKIM to email // check if we can add the DKIM to email
if ($conf->get('enable_dkim')) if ($conf->get('enable_dkim'))
{ {
@ -244,20 +270,20 @@ abstract class ComponentbuilderEmail
$mail->DKIM_private = $tmp; $mail->DKIM_private = $tmp;
} }
} }
$sendmail = $mail->Send(); $sendmail = $mail->Send();
if ($conf->get('enable_dkim') && !empty($conf->get('dkim_domain')) && !empty($conf->get('dkim_selector')) && !empty($conf->get('dkim_private')) && !empty($conf->get('dkim_public'))) if ($conf->get('enable_dkim') && !empty($conf->get('dkim_domain')) && !empty($conf->get('dkim_selector')) && !empty($conf->get('dkim_private')) && !empty($conf->get('dkim_public')))
{ {
@unlink($tmp); @unlink($tmp);
} }
if (method_exists('ComponentbuilderHelper','storeMessage')) if (method_exists('ComponentbuilderHelper','storeMessage'))
{ {
// store the massage if the method is set // store the massage if the method is set
ComponentbuilderHelper::storeMessage($sendmail, $recipient, $subject, $body, $textonly, $mode, 'email'); ComponentbuilderHelper::storeMessage($sendmail, $recipient, $subject, $body, $textonly, $mode, 'email');
} }
return $sendmail; return $sendmail;
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>15th June, 2018</creationDate> <creationDate>21st June, 2018</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>