invoiceninja/app/Mail/TemplateEmail.php
michael-hampton f7650d0692
Ft email (#3326)
* Emails

* change to user service

* refactor emails

* refactor emails

* refactor emails

* refactor emails

* emails

* emails

* emails

* emails

* emails

* emails

* emails

* emails

* emails

* emails

* Update EmailPayment.php

* Update SendEmail.php

* Update SendEmail.php

* Update SendEmail.php

* Update and rename BuildEmail.php to EmailBuilder.php

* Create InvoiceEmail

* Create QuoteEmail.php

* Rename InvoiceEmail to InvoiceEmail.php

* Create PaymentEmail.php

* Update SendEmail.php

* Update SendEmail.php

* Update SendEmail.php

* Update SendEmail.php

* Update InvoiceEmail.php

* Update EmailInvoice.php

* Update SendEmail.php

* Update TemplateEmail.php

* Update EmailBuilder.php

* Update InvoiceEmail.php

* Update QuoteEmail.php

* Update PaymentEmail.php

* Update InvoiceEmail.php

* Update QuoteEmail.php

* Update QuoteInvitation.php

* Update EmailQuote.php

* Update SendEmail.php

* Update SendEmail.php

* Update PaymentService.php

* Update PaymentEmail.php

* Update PaymentEmail.php

* Update PaymentEmail.php

* Update EmailBuilder.php

* Update PaymentEmail.php

* Update EmailPayment.php

* Update SendEmail.php

* Update InvoiceService.php

* Update SendEmail.php

* Update PaymentService.php

* Update SendEmail.php

* Update QuoteService.php

* Update EmailPayment.php

Co-authored-by: David Bomba <turbo124@gmail.com>
2020-02-15 20:01:15 +11:00

61 lines
2.1 KiB
PHP

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TemplateEmail extends Mailable
{
use Queueable, SerializesModels;
private $build_email; //the message array // ['body', 'footer', 'title', 'files']
private $user; //the user the email will be sent from
private $customer;
private $footer;
public function __construct($build_email, $user, $customer)
{
$this->build_email = $build_email;
$this->user = $user; //this is inappropriate here, need to refactor 'user' in this context the 'user' could also be the 'system'
$this->customer = $customer;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
/*Alter Run Time Mailer configuration (driver etc etc) to regenerate the Mailer Singleton*/
//if using a system level template
$template_name = 'email.template.' . $this->build_email->getTemplate();
$settings = $this->customer->getMergedSettings();
\Log::error(print_r($settings, 1));
$company = $this->customer->account;
$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;
}
}