Initial commit
This commit is contained in:
69
app/Mail/ContactFormMailable.php
Normal file
69
app/Mail/ContactFormMailable.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class ContactFormMailable extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $contact;
|
||||
public $locale;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($contact)
|
||||
{
|
||||
$this->contact = $contact;
|
||||
|
||||
// Determine locale from profile lang_preference or browser locale
|
||||
if (!empty($contact['profile_lang_preference'])) {
|
||||
$this->locale = $contact['profile_lang_preference'];
|
||||
} elseif (!empty($contact['browser_locale'])) {
|
||||
$this->locale = $contact['browser_locale'];
|
||||
} else {
|
||||
$this->locale = config('app.fallback_locale');
|
||||
}
|
||||
|
||||
// Ensure locale is not empty
|
||||
if (empty($this->locale)) {
|
||||
$this->locale = config('app.fallback_locale');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
// Set the application locale for this email
|
||||
app()->setLocale($this->locale);
|
||||
|
||||
$context = $this->contact['context'] ?? 'contact';
|
||||
|
||||
$subject = match($context) {
|
||||
'report-issue' => __('Issue Report') . ': ' . ($this->contact['subject'] ?? __('No subject')),
|
||||
'report-error' => __('Error Report from') . ' ' . $this->contact['full_name'],
|
||||
'delete-profile' => __('Profile Deletion Request from') . ' ' . $this->contact['name'],
|
||||
default => __('Contact Form') . ': ' . ($this->contact['subject'] ?? __('Message from') . ' ' . $this->contact['full_name']),
|
||||
};
|
||||
|
||||
return $this->from(timebank_config('mail.support.email'), timebank_config('mail.support.name'))
|
||||
->replyTo($this->contact['email'], $this->contact['full_name'])
|
||||
->subject($subject)
|
||||
->view('emails.contact-form.email')
|
||||
->with([
|
||||
'contact' => $this->contact,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user