EmlMail.php
1 <?php 2 3 namespace App\Mail; 4 5 use App\Models\EMLTemplate; 6 use Illuminate\Mail\Mailable; 7 use Illuminate\Mail\Mailables\Content; 8 use Illuminate\Mail\Mailables\Envelope; 9 use Illuminate\Queue\SerializesModels; 10 use Illuminate\Support\Facades\Blade; 11 12 class EmlMail extends Mailable 13 { 14 use SerializesModels; 15 16 /** 17 * @var array|mixed 18 */ 19 private mixed $data; 20 21 public $mailer = 'self_destruct'; 22 23 private EMLTemplate $template; 24 private ?string $texSubject; 25 private ?string $textBody; 26 27 /** 28 * Create a new message instance. 29 * 30 * @return void 31 */ 32 public function __construct(bool $encrypt, $view, $data, $from, $to, $bcc, $cc, ?string $subject = null, string $body = null) 33 { 34 $this->template = EMLTemplate::findOrFail($view); 35 36 $this->mailer('self_destruct'); 37 $this->from = $from; 38 $this->to = $to; 39 $this->bcc = $bcc; 40 $this->cc = $cc; 41 $this->texSubject = $subject ?? 'CCN-OC E-Mail'; 42 $this->textBody = $body; 43 $this->subject = $this->texSubject ?? Blade::render($this->template->subject, $this->data['data'] ?? []); 44 45 if ($encrypt) { 46 $this->textView = 'EML_templates.encrypted'; 47 $this->data = []; 48 } else { 49 $this->textView = 'EML_templates.render'; 50 $this->data = [ 51 'template' => $this->template, 52 'data' => $data, 53 'texSubject' => $this->texSubject, 54 ]; 55 } 56 } 57 58 /** 59 * Get the message envelope. 60 * 61 * @return \Illuminate\Mail\Mailables\Envelope 62 */ 63 public function envelope() 64 { 65 return new Envelope( 66 subject: $this->texSubject ?? Blade::render($this->template->subject, $this->data['data'] ?? []) 67 ); 68 } 69 70 /** 71 * Get the message content definition. 72 * 73 * @return \Illuminate\Mail\Mailables\Content 74 */ 75 public function content() 76 { 77 return new Content( 78 view: $this->view, 79 with: $this->data 80 ); 81 } 82 83 /** 84 * Get the attachments for the message. 85 * 86 * @return array 87 */ 88 public function attachments() 89 { 90 return []; 91 } 92 }