NEW: Added Email::send_all_emails_from() setting.

This commit is contained in:
Sam Minnee 2011-03-02 18:23:07 +13:00 committed by Ingo Schommer
parent 5e6f5f9f7e
commit c3a3ff4438
2 changed files with 31 additions and 4 deletions

View File

@ -41,6 +41,7 @@
*
* Email:
* - SS_SEND_ALL_EMAILS_TO: If you set this define, all emails will be redirected to this address.
* - SS_SEND_ALL_EMAILS_FROM: If you set this define, all emails will be send from this address.
*
* @package framework
* @subpackage core
@ -107,6 +108,9 @@ if(defined('SS_DATABASE_USERNAME') && defined('SS_DATABASE_PASSWORD')) {
if(defined('SS_SEND_ALL_EMAILS_TO')) {
Config::inst()->update("Email","send_all_emails_to", SS_SEND_ALL_EMAILS_TO);
}
if(defined('SS_SEND_ALL_EMAILS_FROM')) {
Config::inst()->update("Email","send_all_emails_from", SS_SEND_ALL_EMAILS_FROM);
}
if(defined('SS_DEFAULT_ADMIN_USERNAME')) {
if(!defined('SS_DEFAULT_ADMIN_PASSWORD')) {

View File

@ -135,6 +135,17 @@ class Email extends ViewableData {
* @param string $send_all_emails_to Email-Address
*/
protected static $send_all_emails_to = null;
/**
* Send every email generated by the Email class *from* the given address.
* It will also add " [, from to (email)]" to the end of the subject line
*
* To set this, set Email.send_all_emails_from in your yml config file.
* It can also be set in _ss_environment.php with SS_SEND_ALL_EMAILS_FROM.
*
* @param string $send_all_emails_from Email-Address
*/
protected static $send_all_emails_from = null;
/**
* BCC every email generated by the Email class to the given address.
@ -426,6 +437,7 @@ class Email extends ViewableData {
if(project()) $headers['X-SilverStripeSite'] = project();
$to = $this->to;
$from = $this->from;
$subject = $this->subject;
if($sendAllTo = $this->config()->send_all_emails_to) {
$subject .= " [addressed to $to";
@ -456,9 +468,14 @@ class Email extends ViewableData {
}
}
if($sendAllfrom = $this->config()->send_all_emails_from) {
if($from) $subject .= " [from $from]";
$from = $sendAllfrom;
}
Requirements::restore();
return self::mailer()->sendPlain($to, $this->from, $subject, $this->body, $this->attachments, $headers);
return self::mailer()->sendPlain($to, $from, $subject, $this->body, $this->attachments, $headers);
}
/**
@ -490,6 +507,7 @@ class Email extends ViewableData {
$to = $this->to;
$from = $this->from;
$subject = $this->subject;
if($sendAllTo = $this->config()->send_all_emails_to) {
$subject .= " [addressed to $to";
@ -521,10 +539,15 @@ class Email extends ViewableData {
$headers['Bcc'] = $bccAllTo;
}
}
if($sendAllfrom = $this->config()->send_all_emails_from) {
if($from) $subject .= " [from $from]";
$from = $sendAllfrom;
}
Requirements::restore();
return self::mailer()->sendHTML($to, $this->from, $subject, $this->body, $this->attachments, $headers,
return self::mailer()->sendHTML($to, $from, $subject, $this->body, $this->attachments, $headers,
$this->plaintext_body);
}
@ -558,7 +581,7 @@ class Email extends ViewableData {
public static function send_all_emails_to($emailAddress) {
self::$send_all_emails_to = $emailAddress;
}
/**
* 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