diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php
index 25dca243d6bf..8329a71337bd 100644
--- a/app/Http/Controllers/EmailController.php
+++ b/app/Http/Controllers/EmailController.php
@@ -23,6 +23,7 @@ use App\Models\Invoice;
use App\Models\PurchaseOrder;
use App\Models\Quote;
use App\Models\RecurringInvoice;
+use App\Services\Email\MailEntity;
use App\Services\Email\MailObject;
use App\Transformers\CreditTransformer;
use App\Transformers\InvoiceTransformer;
@@ -129,6 +130,10 @@ class EmailController extends BaseController
];
$mo = new MailObject;
+ $mo->subject = empty($subject) ? null : $subject;
+ $mo->body = empty($body) ? null : $body;
+ $mo->entity_string = $entity;
+ $mo->email_template = $template;
if(Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);
@@ -137,12 +142,14 @@ class EmailController extends BaseController
return $this->sendPurchaseOrder($entity_obj, $data, $template);
}
- $entity_obj->invitations->each(function ($invitation) use ($data, $entity_string, $entity_obj, $template) {
+ $entity_obj->invitations->each(function ($invitation) use ($data, $entity_string, $entity_obj, $template, $mo) {
if (! $invitation->contact->trashed() && $invitation->contact->email) {
$entity_obj->service()->markSent()->save();
- EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data);
+ // EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data);
+
+ MailEntity::dispatch($invitation, $invitation->company->db, $mo);
}
});
diff --git a/app/Services/Email/MailBuild.php b/app/Services/Email/MailBuild.php
index e9e9b4aa902b..222368dd3ab6 100644
--- a/app/Services/Email/MailBuild.php
+++ b/app/Services/Email/MailBuild.php
@@ -286,8 +286,8 @@ class MailBuild
if ($this->mail_entity->mail_object->subject) //where the user updates the subject from the UI
return $this;
- elseif(is_string($this->mail_entity->mail_object->email_template_subject) && strlen($this->settings->{$this->mail_entity->mail_object->email_template_subject}) > 3)
- $this->mail_entity->mail_object->subject = $this->settings->{$this->mail_entity->mail_object->email_template_subject};
+ elseif(is_string($this->mail_entity->mail_object->email_template) && strlen($this->settings->{$this->resolveBaseEntityTemplate()}) > 3)
+ $this->mail_entity->mail_object->subject = $this->settings->{$this->resolveBaseEntityTemplate()};
else
$this->mail_entity->mail_object->subject = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate(), $this->locale);
@@ -306,8 +306,8 @@ class MailBuild
if($this->mail_entity->mail_object->body){
$this->mail_entity->mail_object->body = $this->mail_entity->mail_object->body;
}
- elseif(is_string($this->mail_entity->mail_object->email_template_body) && strlen($this->settings->{$this->mail_entity->mail_object->email_template_body}) > 3){
- $this->mail_entity->mail_object->body = $this->settings->{$this->mail_entity->mail_object->email_template_body};
+ elseif(is_string($this->mail_entity->mail_object->email_template) && strlen($this->settings->{$this->resolveBaseEntityTemplate('body')}) > 3){
+ $this->mail_entity->mail_object->body = $this->settings->{$this->resolveBaseEntityTemplate('body')};
}
else{
$this->mail_entity->mail_object->body = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate('body'), $this->locale);
@@ -330,6 +330,17 @@ class MailBuild
*/
private function resolveBaseEntityTemplate(string $type = 'subject'): string
{
+ if($this->mail_entity->mail_object->email_template){
+
+ match($type){
+ 'subject' => $template = "email_subject_{$this->mail_entity->mail_object->email_template}",
+ 'body' => $template = "email_template_{$this->mail_entity->mail_object->email_template}",
+ default => $template = "email_template_invoice",
+ };
+
+ return $template;
+ }
+
//handle statements being emailed
//handle custom templates these types won't have a resolvable entity_string
if(!$this->mail_entity->mail_object->entity_string)
diff --git a/app/Services/Email/MailMailable.php b/app/Services/Email/MailMailable.php
index d88a6a62ded9..4d0dd5008e66 100644
--- a/app/Services/Email/MailMailable.php
+++ b/app/Services/Email/MailMailable.php
@@ -57,7 +57,7 @@ class MailMailable extends Mailable
view: $this->mail_object->html_template,
text: $this->mail_object->text_template,
with: [
- 'text_body' => strip_tags($this->mail_object->body), //@todo this is a bit hacky here.
+ 'text_body' => str_replace("
","\n", strip_tags($this->mail_object->body,"
")), //@todo this is a bit hacky here.
'body' => $this->mail_object->body,
'settings' => $this->mail_object->settings,
'whitelabel' => $this->mail_object->whitelabel,
diff --git a/app/Services/Email/MailObject.php b/app/Services/Email/MailObject.php
index 30ace3436ec7..d5788ce00c42 100644
--- a/app/Services/Email/MailObject.php
+++ b/app/Services/Email/MailObject.php
@@ -62,9 +62,7 @@ class MailObject
public ?int $vendor_contact_id = null;
- public ?string $email_template_body = null;
-
- public ?string $email_template_subject = null;
+ public ?string $email_template = null; //this defines the template in short notation WITH the email_template prefix
public ?string $html_template = null;