From b73a3cdd7ab092a3dd02b78d51e48f97867c4f8e Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 8 Mar 2022 14:31:51 +1300 Subject: [PATCH] API Extension hook for email default from --- docs/en/02_Developer_Guides/10_Email/index.md | 2 ++ src/Control/Email/Email.php | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/en/02_Developer_Guides/10_Email/index.md b/docs/en/02_Developer_Guides/10_Email/index.md index 15ed00fba..7954e3384 100644 --- a/docs/en/02_Developer_Guides/10_Email/index.md +++ b/docs/en/02_Developer_Guides/10_Email/index.md @@ -215,6 +215,8 @@ email marked as spam. If you want to send from another address think about using You will also have to remove the `SS_SEND_ALL_EMAILS_FROM` environment variable if it is present. +If you need greater control over this email address, for instance if are running the subsites modules, you can implement the `SilverStripe\Control\Email\Email::updateDefaultFrom()` extension hook. + ## Redirecting Emails There are several other [configuration settings](/developer_guides/configuration) to manipulate the email server. diff --git a/src/Control/Email/Email.php b/src/Control/Email/Email.php index 7396a129c..793e44d2b 100644 --- a/src/Control/Email/Email.php +++ b/src/Control/Email/Email.php @@ -297,6 +297,7 @@ class Email extends ViewableData } $defaultFrom = sprintf('no-reply@%s', $host); } + $this->extend('updateDefaultFrom', $defaultFrom); return $defaultFrom; }