Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NEW: Added Email::send_all_emails_from() setting.

  • Loading branch information...
commit c3a3ff4438f91d23ddc8ef1617e866c3a1f0692d 1 parent 5e6f5f9
@sminnee sminnee authored chillu committed
Showing with 31 additions and 4 deletions.
  1. +4 −0 conf/ConfigureFromEnv.php
  2. +27 −4 email/Email.php
View
4 conf/ConfigureFromEnv.php
@@ -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_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
31 email/Email.php
@@ -135,6 +135,17 @@ public static function mailer() {
* @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 @@ public function sendPlain($messageID = null) {
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 @@ public function sendPlain($messageID = null) {
}
}
+ 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 @@ public function send($messageID = null) {
$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 @@ public function send($messageID = null) {
$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 @@ public static function getAdminEmail() {
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
Please sign in to comment.
Something went wrong with that request. Please try again.