41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\EmailLog;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
abstract class MailableBase extends Mailable
|
|
{
|
|
public function buildEmailLog()
|
|
{
|
|
// Build the e-mail
|
|
$this->build();
|
|
|
|
// Get the current user for the ID
|
|
$currentUser = Auth::user();
|
|
|
|
// Build the body so we can use it as a string
|
|
$bodies = $this->buildView();
|
|
|
|
/** @var HtmlString $html */
|
|
$html = $bodies['html'];
|
|
|
|
/** @var HtmlString $text */
|
|
$text = $bodies['text'];
|
|
|
|
return new EmailLog([
|
|
'sender_user_id' => !is_null($currentUser) ? $currentUser->id : null,
|
|
'sender_name' => $this->from[0]['name'],
|
|
'sender_address' => $this->from[0]['address'],
|
|
'to_addresses' => json_encode($this->to),
|
|
'cc_addresses' => json_encode($this->cc),
|
|
'bcc_addresses' => json_encode($this->bcc),
|
|
'subject' => $this->subject,
|
|
'body_plain' => $text->toHtml(),
|
|
'body_html' => $html->toHtml()
|
|
]);
|
|
}
|
|
} |