Skip to content

Commit

Permalink
allow forcing sender
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Mar 10, 2021
1 parent f3166bd commit 4707af8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/SparkPostAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public function getEditForm($id = null, $fields = null)
if (SparkPostHelper::getEnvSubaccountId()) {
$toolsHtml .= '<p style="color:orange">Using subaccount id</p>';
}
if (SparkPostHelper::getEnvForceSender()) {
$toolsHtml .= '<p style="color:orange">Sender is forced to ' . SparkPostHelper::getEnvForceSender() . '</p>';
}

// Add a refresh button
$toolsHtml .= $this->ButtonHelper(
Expand Down
5 changes: 5 additions & 0 deletions src/SparkPostHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public static function getEnvSubaccountId()
return Environment::getEnv('SPARKPOST_SUBACCOUNT_ID');
}

public static function getEnvForceSender()
{
return Environment::getEnv('SPARKPOST_FORCE_SENDER');
}

/**
* Register the transport with the client
*
Expand Down
4 changes: 3 additions & 1 deletion src/SparkPostSwiftTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,14 @@ public function getTransmissionFromMessage(Swift_Mime_Message $message)

$fromAddresses = $message->getFrom();

$fromEmails = array_keys($fromAddresses);
$fromFirstEmail = key($fromAddresses);
$fromFirstName = current($fromAddresses);
if (SparkPostHelper::config()->override_admin_email && SparkPostHelper::isAdminEmail($fromFirstEmail)) {
$fromFirstEmail = SparkPostHelper::resolveDefaultFromEmail();
}
if (SparkPostHelper::getEnvForceSender()) {
$fromFirstEmail = SparkPostHelper::getEnvForceSender();
}
if (!$fromFirstName) {
$fromFirstName = EmailUtils::get_displayname_from_rfc_email($fromFirstEmail);
}
Expand Down

0 comments on commit 4707af8

Please sign in to comment.