Double check your .env has correct mail settings to allow sending
Add configuration to your app config
'email_test_mode' => true,
'test_emails' => array(
'test@meccamedialight.com.au',
),
'booking_notifications_email' => ['test@meccamedialight.com.au'],
'publish_notifications_email' => ['test@meccamedialight.com.au'],
'contact_notifications_email' => ['test@meccamedialight.com.au'],
'expiry_notifications_email' => ['test@meccamedialight.com.au'],
Add a Mailable for the mail you wish to send
app/Mail/ContactSubmittedAdmin.php
<?php
namespace App\Mail;
use App\Models\Contact;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ContactSubmittedAdmin extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(public Contact $contact)
{
//
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Contact form submitted '.$this->contact->name,
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'emails.admin.contact-form-submitted',
);
}
/**
* Get the attachments for the message.
*
* <int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
app/Actions/ContactFormSubmitted.php
<?php
namespace App\Actions;
use App\Mail\ContactSubmittedAdmin;
use App\Models\Contact;
use Exception;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
class ContactFormSubmitted
{
private $contact;
public function __construct()
{
// $this->memberRules = $memberRules;
}
public function contacted(Contact $contact)
{
//Notify admin
$testMode = Config::get('textstemapp.email_test_mode');
$allowedTestEmails = Config::get('textstemapp.test_emails');
$notifyEmail = Config::get('textstemapp.contact_notifications_email');
foreach ($notifyEmail as $admin) {
try {
if(!$testMode){
$ok = Mail::to($admin)->send(new ContactSubmittedAdmin($contact));
}
else if (in_array($admin, $allowedTestEmails, true)){
Mail::to($admin)->send(new ContactSubmittedAdmin($contact));
}
} catch (Exception $e){
Log::error("Failed to send contact notify email ". $e->getMessage());
}
}
return [];
}
}
Add the email template
resources/views/emails/admin/contact-form-submitted.blade.php
<x-mail::message>
<h2>There has been a contact form submission</h2>
<x-mail::table>
| | |
|:----------------------- |:---------------------------|
| Request created | {{$contact->created_at}} |
| Customer Name | {{$contact->name}} |
| Company? | {{$contact->company}} |
| email | {{$contact->email}} |
| Comment | {{$contact->body}} |
</x-mail::table>
Thanks,<br>
{{ config('app.name') }}
</x-mail::message>