1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00
invoiceninja/app/Mail/TemplateEmail.php

74 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Mail;
2020-02-15 12:49:31 +01:00
use App\Models\Client;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TemplateEmail extends Mailable
{
use Queueable, SerializesModels;
2020-02-15 12:49:31 +01:00
private $build_email;
private $user; //the user the email will be sent from
2020-02-15 12:49:31 +01:00
private $client;
private $footer;
2020-02-15 12:49:31 +01:00
public function __construct($build_email, User $user, Client $client)
{
2020-02-15 12:49:31 +01:00
$this->build_email = $build_email;
2020-02-15 12:49:31 +01:00
$this->user = $user; //this is inappropriate here, need to refactor 'user' in this context the 'user' could also be the 'system'
2020-02-15 12:49:31 +01:00
$this->client = $client;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
/*Alter Run Time Mailer configuration (driver etc etc) to regenerate the Mailer Singleton*/
2020-02-15 12:49:31 +01:00
//if using a system level template
$template_name = 'email.template.' . $this->build_email->getTemplate();
2020-02-15 12:49:31 +01:00
$settings = $this->client->getMergedSettings();
$company = $this->client->company;
2020-02-15 12:49:31 +01:00
$message = $this->from($this->user->email,$this->user->present()->name())//todo this needs to be fixed to handle the hosted version
->subject($this->build_email->getSubject())
->text('email.template.plain', [
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter()
])
->view($template_name, [
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter(),
'title' => $this->build_email->getSubject(),
'settings' => $settings,
'company' => $company
]);
//conditionally attach files
if($settings->pdf_email_attachment !== false && !empty($this->build_email->getAttachments())){
foreach($this->build_email->getAttachments() as $file)
$message->attach($file);
}
return $message;
}
}