Skip to content

Commit

Permalink
Merge pull request #26 from kuzmany/fix-owner_is_mailer
Browse files Browse the repository at this point in the history
Fix owner is mailer
  • Loading branch information
jos0405 authored Mar 31, 2024
2 parents b3ca702 + c8a0694 commit 60cc2ac
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions EventListener/BuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public function onEmailGenerate(EmailSendEvent $event)
$lead = $event->getLead();
$email = $event->getEmail();
$senderEmail = null;
$senderDomain = null;
$senderDomain = null;

if(!$email instanceof Email){
return;
}

if (null == $idHash) {
// Generate a bogus idHash to prevent errors for routes that may include it
Expand All @@ -136,12 +140,18 @@ public function onEmailGenerate(EmailSendEvent $event)

// Check if the Mailer is Owner is set, if not then search the sender email from Email channels From address
// And finally if nothing is set, use the mailer from email if it is not blank.
if($this->coreParametersHelper->get('mailer_is_owner') && $lead['id']){
$senderEmail = $lead['email'];
}else if($email && $email->getFromAddress()){
$senderEmail = $this->coreParametersHelper->get("mailer_from_email");
$mailerIsOwnerGlobal = $this->coreParametersHelper->get('mailer_is_owner');
$mailerIsOwner = $email->getUseOwnerAsMailer();

if(($mailerIsOwnerGlobal || $mailerIsOwner) && $lead['id']){
$ownerEmail = $event->getTokens()['{ownerfield=email}'] ?? null;
if (!empty($ownerEmail)) {
$senderEmail = $ownerEmail;
}
}
if(empty($ownerEmail) && $email && $email->getFromAddress()){
$senderEmail = $email->getFromAddress();
}else{
$senderEmail = $this->coreParametersHelper->get("mailer_from_email");
}

if($senderEmail){
Expand Down

0 comments on commit 60cc2ac

Please sign in to comment.