feat(contact): email submissions to support and owner inbox
Deploy Backend / deploy (push) Successful in 3m53s

Store contact messages as before, then notify support@parsaaghayi.ir
and parsa.aghaee@gmail.com via SMTP-ready mail config. Failures are
logged without blocking the 201 response; PHPUnit covers both recipients.
This commit is contained in:
Parsa Aghayi committed 2026-11-10 11:12:11 +00:00
1 parent eda889e166
commit 1c8086bad1
7 files changed
+147 -12

No files matched your search

@@ -3,9 +3,12 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Mail\ContactMessageReceived;
use App\Models\ContactMessage;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
/**
* @OA\Tag(name="Contact", description="Contact form submissions")
@@ -15,8 +18,8 @@ class ContactMessageController extends Controller
/**
* Public contact form submission.
*
* The site has no mail service of its own; messages are stored in the
* database and read from the admin panel instead of being emailed.
* Messages are stored for the admin panel and emailed to the support
* mailbox plus the owner notification address.
*/
public function store(Request $request): JsonResponse
{
@@ -32,6 +35,18 @@ class ContactMessageController extends Controller
'message' => $validated['message'],
]);
$recipients = config('contact.notify', []);
if ($recipients !== []) {
try {
Mail::to($recipients)->send(new ContactMessageReceived($message));
} catch (\Throwable $e) {
Log::error('Contact form notification email failed', [
'contact_message_id' => $message->id,
'error' => $e->getMessage(),
]);
}
}
return response()->json(['message' => 'پیام شما با موفقیت ثبت شد.'], 201);
}
@@ -67,4 +82,4 @@ class ContactMessageController extends Controller
return response()->json(null, 200);
}
}
}