mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-01 05:39:10 +02:00
NEW: Allow configuration of send_all_emails_to, ccs_all_emails_to, and bcc_all_emails_to via the config system.
This commit is contained in:
parent
7026a488e6
commit
5e6f5f9f7e
@ -105,7 +105,7 @@ if(defined('SS_DATABASE_USERNAME') && defined('SS_DATABASE_PASSWORD')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(defined('SS_SEND_ALL_EMAILS_TO')) {
|
if(defined('SS_SEND_ALL_EMAILS_TO')) {
|
||||||
Email::send_all_emails_to(SS_SEND_ALL_EMAILS_TO);
|
Config::inst()->update("Email","send_all_emails_to", SS_SEND_ALL_EMAILS_TO);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(defined('SS_DEFAULT_ADMIN_USERNAME')) {
|
if(defined('SS_DEFAULT_ADMIN_USERNAME')) {
|
||||||
|
@ -263,6 +263,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->originalMailer = Email::mailer();
|
$this->originalMailer = Email::mailer();
|
||||||
$this->mailer = new TestMailer();
|
$this->mailer = new TestMailer();
|
||||||
Email::set_mailer($this->mailer);
|
Email::set_mailer($this->mailer);
|
||||||
|
Config::inst()->remove('Email', 'send_all_emails_to');
|
||||||
Email::send_all_emails_to(null);
|
Email::send_all_emails_to(null);
|
||||||
|
|
||||||
// Preserve memory settings
|
// Preserve memory settings
|
||||||
|
@ -125,16 +125,43 @@ class Email extends ViewableData {
|
|||||||
static $admin_email_address = '';
|
static $admin_email_address = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send every email generated by the Email class to the given address.
|
||||||
|
*
|
||||||
|
* It will also add " [addressed to (email), cc to (email), bcc to (email)]" to the end of the subject line
|
||||||
|
*
|
||||||
|
* To set this, set Email.send_all_emails_to in your yml config file.
|
||||||
|
* It can also be set in _ss_environment.php with SS_SEND_ALL_EMAILS_TO.
|
||||||
|
*
|
||||||
* @param string $send_all_emails_to Email-Address
|
* @param string $send_all_emails_to Email-Address
|
||||||
*/
|
*/
|
||||||
protected static $send_all_emails_to = null;
|
protected static $send_all_emails_to = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* BCC every email generated by the Email class to the given address.
|
||||||
|
* It won't affect the original delivery in the same way that send_all_emails_to does. It just adds a BCC header
|
||||||
|
* with the given email address. Note that you can only call this once - subsequent calls will overwrite the
|
||||||
|
* configuration variable.
|
||||||
|
*
|
||||||
|
* This can be used when you have a system that relies heavily on email and you want someone to be checking all
|
||||||
|
* correspondence.
|
||||||
|
*
|
||||||
|
* To set this, set Email.bcc_all_emails_to in your yml config file.
|
||||||
|
*
|
||||||
* @param string $bcc_all_emails_to Email-Address
|
* @param string $bcc_all_emails_to Email-Address
|
||||||
*/
|
*/
|
||||||
protected static $bcc_all_emails_to = null;
|
protected static $bcc_all_emails_to = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* CC every email generated by the Email class to the given address.
|
||||||
|
* It won't affect the original delivery in the same way that send_all_emails_to does. It just adds a CC header
|
||||||
|
* with the given email address. Note that you can only call this once - subsequent calls will overwrite the
|
||||||
|
* configuration variable.
|
||||||
|
*
|
||||||
|
* This can be used when you have a system that relies heavily on email and you want someone to be checking all
|
||||||
|
* correspondence.
|
||||||
|
*
|
||||||
|
* To set this, set Email.cc_all_emails_to in your yml config file.
|
||||||
|
*
|
||||||
* @param string $cc_all_emails_to Email-Address
|
* @param string $cc_all_emails_to Email-Address
|
||||||
*/
|
*/
|
||||||
protected static $cc_all_emails_to = null;
|
protected static $cc_all_emails_to = null;
|
||||||
@ -400,30 +427,32 @@ class Email extends ViewableData {
|
|||||||
|
|
||||||
$to = $this->to;
|
$to = $this->to;
|
||||||
$subject = $this->subject;
|
$subject = $this->subject;
|
||||||
if(self::$send_all_emails_to) {
|
if($sendAllTo = $this->config()->send_all_emails_to) {
|
||||||
$subject .= " [addressed to $to";
|
$subject .= " [addressed to $to";
|
||||||
$to = self::$send_all_emails_to;
|
$to = $sendAllTo;
|
||||||
if($this->cc) $subject .= ", cc to $this->cc";
|
if($this->cc) $subject .= ", cc to $this->cc";
|
||||||
if($this->bcc) $subject .= ", bcc to $this->bcc";
|
if($this->bcc) $subject .= ", bcc to $this->bcc";
|
||||||
$subject .= ']';
|
$subject .= ']';
|
||||||
|
unset($headers['Cc']);
|
||||||
|
unset($headers['Bcc']);
|
||||||
} else {
|
} else {
|
||||||
if($this->cc) $headers['Cc'] = $this->cc;
|
if($this->cc) $headers['Cc'] = $this->cc;
|
||||||
if($this->bcc) $headers['Bcc'] = $this->bcc;
|
if($this->bcc) $headers['Bcc'] = $this->bcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self::$cc_all_emails_to) {
|
if($ccAllTo = $this->config()->cc_all_emails_to) {
|
||||||
if(!empty($headers['Cc']) && trim($headers['Cc'])) {
|
if(!empty($headers['Cc']) && trim($headers['Cc'])) {
|
||||||
$headers['Cc'] .= ', ' . self::$cc_all_emails_to;
|
$headers['Cc'] .= ', ' . $ccAllTo;
|
||||||
} else {
|
} else {
|
||||||
$headers['Cc'] = self::$cc_all_emails_to;
|
$headers['Cc'] = $ccAllTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self::$bcc_all_emails_to) {
|
if($bccAllTo = $this->config()->bcc_all_emails_to) {
|
||||||
if(!empty($headers['Bcc']) && trim($headers['Bcc'])) {
|
if(!empty($headers['Bcc']) && trim($headers['Bcc'])) {
|
||||||
$headers['Bcc'] .= ', ' . self::$bcc_all_emails_to;
|
$headers['Bcc'] .= ', ' . $bccAllTo;
|
||||||
} else {
|
} else {
|
||||||
$headers['Bcc'] = self::$bcc_all_emails_to;
|
$headers['Bcc'] = $bccAllTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,34 +488,37 @@ class Email extends ViewableData {
|
|||||||
|
|
||||||
if(project()) $headers['X-SilverStripeSite'] = project();
|
if(project()) $headers['X-SilverStripeSite'] = project();
|
||||||
|
|
||||||
|
|
||||||
$to = $this->to;
|
$to = $this->to;
|
||||||
$subject = $this->subject;
|
$subject = $this->subject;
|
||||||
if(self::$send_all_emails_to) {
|
if($sendAllTo = $this->config()->send_all_emails_to) {
|
||||||
$subject .= " [addressed to $to";
|
$subject .= " [addressed to $to";
|
||||||
$to = self::$send_all_emails_to;
|
$to = $sendAllTo;
|
||||||
if($this->cc) $subject .= ", cc to $this->cc";
|
if($this->cc) $subject .= ", cc to $this->cc";
|
||||||
if($this->bcc) $subject .= ", bcc to $this->bcc";
|
if($this->bcc) $subject .= ", bcc to $this->bcc";
|
||||||
$subject .= ']';
|
$subject .= ']';
|
||||||
unset($headers['Cc']);
|
unset($headers['Cc']);
|
||||||
unset($headers['Bcc']);
|
unset($headers['Bcc']);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if($this->cc) $headers['Cc'] = $this->cc;
|
if($this->cc) $headers['Cc'] = $this->cc;
|
||||||
if($this->bcc) $headers['Bcc'] = $this->bcc;
|
if($this->bcc) $headers['Bcc'] = $this->bcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self::$cc_all_emails_to) {
|
|
||||||
|
if($ccAllTo = $this->config()->cc_all_emails_to) {
|
||||||
if(!empty($headers['Cc']) && trim($headers['Cc'])) {
|
if(!empty($headers['Cc']) && trim($headers['Cc'])) {
|
||||||
$headers['Cc'] .= ', ' . self::$cc_all_emails_to;
|
$headers['Cc'] .= ', ' . $ccAllTo;
|
||||||
} else {
|
} else {
|
||||||
$headers['Cc'] = self::$cc_all_emails_to;
|
$headers['Cc'] = $ccAllTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self::$bcc_all_emails_to) {
|
if($bccAllTo = $this->config()->bcc_all_emails_to) {
|
||||||
if(!empty($headers['Bcc']) && trim($headers['Bcc'])) {
|
if(!empty($headers['Bcc']) && trim($headers['Bcc'])) {
|
||||||
$headers['Bcc'] .= ', ' . self::$bcc_all_emails_to;
|
$headers['Bcc'] .= ', ' . $bccAllTo;
|
||||||
} else {
|
} else {
|
||||||
$headers['Bcc'] = self::$bcc_all_emails_to;
|
$headers['Bcc'] = $bccAllTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user