feat(contact): send confirmation email to form submitter
Deploy Backend / deploy (push) Successful in 47s

Keep admin notify to CONTACT_NOTIFY_TO and also mail the submitter a branded confirmation so testers are not confused by missing inbox mail.
This commit is contained in:
Parsa Aghayi committed 2026-11-10 13:15:36 +00:00
1 parent 1c8086bad1
commit fa32df60a9
7 files changed
+158 -15

No files matched your search

@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Mail\ContactMessageConfirmed;
use App\Mail\ContactMessageReceived;
use App\Models\ContactMessage;
use Illuminate\Http\JsonResponse;
@@ -47,6 +48,15 @@ class ContactMessageController extends Controller
}
}
try {
Mail::to($message->email)->send(new ContactMessageConfirmed($message));
} catch (\Throwable $e) {
Log::error('Contact form confirmation email failed', [
'contact_message_id' => $message->id,
'error' => $e->getMessage(),
]);
}
return response()->json(['message' => 'پیام شما با موفقیت ثبت شد.'], 201);
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Mail;
use App\Models\ContactMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ContactMessageConfirmed extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public ContactMessage $contactMessage)
{
}
public function envelope(): Envelope
{
return new Envelope(
subject: 'پیام شما در پارساآقایی ثبت شد',
);
}
public function content(): Content
{
return new Content(
html: 'mail.contact-message-confirmed',
text: 'mail.contact-message-confirmed-text',
);
}
}
@@ -0,0 +1,13 @@
پارسا آقایی | پیام شما ثبت شد
سلام {{ $contactMessage->name }}،
پیام شما از طریق فرم تماس سایت با موفقیت ثبت شد. به‌زودی بررسی می‌کنم و در صورت نیاز پاسخ می‌دهم.
خلاصه پیام:
{{ $contactMessage->message }}
شناسه پیگیری: #{{ $contactMessage->id }}
—
parsaaghayi.ir · support@parsaaghayi.ir
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>پیام شما ثبت شد</title>
</head>
<body style="margin:0;padding:0;background:#f4f4f5;color:#09090b;font-family:Tahoma,Arial,sans-serif;line-height:1.8;font-size:15px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;background:#f4f4f5;">
<tr>
<td align="center" style="padding:28px 14px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;max-width:640px;background:#ffffff;text-align:right;">
<tr>
<td style="padding:22px 28px;border-bottom:1px solid #e4e4e7;background:#09090b;">
<p style="margin:0;font-size:11px;letter-spacing:0.18em;color:#a1a1aa;text-transform:uppercase;">PARSA AGHAYI</p>
<p style="margin:8px 0 0;font-size:22px;font-weight:700;color:#ffffff;">پارسا آقایی</p>
<p style="margin:6px 0 0;font-size:13px;color:#FD6F00;">پیام شما ثبت شد</p>
</td>
</tr>
<tr>
<td style="padding:28px;">
<p style="margin:0 0 12px;">سلام {{ $contactMessage->name }}،</p>
<p style="margin:0 0 16px;color:#52525b;">پیام شما از طریق فرم تماس سایت با موفقیت ثبت شد. به‌زودی بررسی می‌کنم و در صورت نیاز پاسخ می‌دهم.</p>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;margin:0 0 16px;">
<tr>
<td style="padding:14px;background:#fafafa;border:1px solid #e4e4e7;border-right:3px solid #FD6F00;">
<p style="margin:0 0 8px;font-size:13px;color:#71717a;">خلاصه پیام شما</p>
<p style="margin:0;white-space:pre-wrap;">{{ $contactMessage->message }}</p>
</td>
</tr>
</table>
<p style="margin:0;font-size:13px;color:#71717a;">شناسه پیگیری: <span dir="ltr">#{{ $contactMessage->id }}</span></p>
</td>
</tr>
<tr>
<td style="padding:18px 28px;background:#09090b;color:#a1a1aa;font-size:12px;">
<span style="color:#FD6F00;">●</span>
parsaaghayi.ir
&nbsp;·&nbsp;
<a href="mailto:support@parsaaghayi.ir" style="color:#ffffff;text-decoration:none;" dir="ltr">support@parsaaghayi.ir</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
@@ -1,4 +1,4 @@
پیام جدید از فرم تماس پارساآقایی
پارسا آقایی | پیام جدید از فرم تماس
نام: {{ $contactMessage->name }}
ایمیل: {{ $contactMessage->email }}
@@ -6,3 +6,6 @@
پیام:
{{ $contactMessage->message }}
—
parsaaghayi.ir · support@parsaaghayi.ir
+41 -14
View File
@@ -2,33 +2,60 @@
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>پیام جدید از فرم تماس</title>
</head>
<body style="font-family: Tahoma, Arial, sans-serif; line-height: 1.7; color: #111;">
<h2 style="margin-bottom: 8px;">پیام جدید از فرم تماس پارساآقایی</h2>
<p style="margin: 0 0 16px;">یک نفر از طریق سایت پیام گذاشته است.</p>
<body style="margin:0;padding:0;background:#f4f4f5;color:#09090b;font-family:Tahoma,Arial,sans-serif;line-height:1.8;font-size:15px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;background:#f4f4f5;">
<tr>
<td align="center" style="padding:28px 14px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;max-width:640px;background:#ffffff;text-align:right;">
<tr>
<td style="padding:22px 28px;border-bottom:1px solid #e4e4e7;background:#09090b;">
<p style="margin:0;font-size:11px;letter-spacing:0.18em;color:#a1a1aa;text-transform:uppercase;">PARSA AGHAYI</p>
<p style="margin:8px 0 0;font-size:22px;font-weight:700;color:#ffffff;">پارسا آقایی</p>
<p style="margin:6px 0 0;font-size:13px;color:#FD6F00;">پیام جدید از فرم تماس</p>
</td>
</tr>
<tr>
<td style="padding:28px;">
<p style="margin:0 0 20px;color:#52525b;">یک نفر از طریق سایت پارساآقایی پیام گذاشته است.</p>
<table cellpadding="8" cellspacing="0" style="border-collapse: collapse; width: 100%; max-width: 640px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td style="border: 1px solid #ddd; width: 120px; background: #f7f7f7;"><strong>نام</strong></td>
<td style="border: 1px solid #ddd;">{{ $contactMessage->name }}</td>
<td style="padding:12px 14px;width:110px;background:#fafafa;border:1px solid #e4e4e7;color:#71717a;font-size:13px;"><strong style="color:#09090b;">نام</strong></td>
<td style="padding:12px 14px;border:1px solid #e4e4e7;">{{ $contactMessage->name }}</td>
</tr>
<tr>
<td style="border: 1px solid #ddd; background: #f7f7f7;"><strong>ایمیل</strong></td>
<td style="border: 1px solid #ddd;" dir="ltr">{{ $contactMessage->email }}</td>
<td style="padding:12px 14px;background:#fafafa;border:1px solid #e4e4e7;color:#71717a;font-size:13px;"><strong style="color:#09090b;">ایمیل</strong></td>
<td style="padding:12px 14px;border:1px solid #e4e4e7;" dir="ltr">{{ $contactMessage->email }}</td>
</tr>
<tr>
<td style="border: 1px solid #ddd; background: #f7f7f7; vertical-align: top;"><strong>پیام</strong></td>
<td style="border: 1px solid #ddd; white-space: pre-wrap;">{{ $contactMessage->message }}</td>
<td style="padding:12px 14px;background:#fafafa;border:1px solid #e4e4e7;color:#71717a;font-size:13px;vertical-align:top;"><strong style="color:#09090b;">پیام</strong></td>
<td style="padding:12px 14px;border:1px solid #e4e4e7;white-space:pre-wrap;">{{ $contactMessage->message }}</td>
</tr>
<tr>
<td style="border: 1px solid #ddd; background: #f7f7f7;"><strong>شناسه</strong></td>
<td style="border: 1px solid #ddd;" dir="ltr">#{{ $contactMessage->id }}</td>
<td style="padding:12px 14px;background:#fafafa;border:1px solid #e4e4e7;color:#71717a;font-size:13px;"><strong style="color:#09090b;">شناسه</strong></td>
<td style="padding:12px 14px;border:1px solid #e4e4e7;" dir="ltr">#{{ $contactMessage->id }}</td>
</tr>
</table>
<p style="margin-top: 20px; font-size: 13px; color: #555;">
این ایمیل به‌صورت خودکار پس از ثبت فرم تماس ارسال شده است.
<p style="margin:24px 0 0;font-size:13px;color:#71717a;">
برای پاسخ مستقیم، روی Reply بزنید؛ آدرس فرستنده همان ایمیل کاربر است.
</p>
</td>
</tr>
<tr>
<td style="padding:18px 28px;background:#09090b;color:#a1a1aa;font-size:12px;">
<span style="color:#FD6F00;">●</span>
parsaaghayi.ir
&nbsp;·&nbsp;
<a href="mailto:support@parsaaghayi.ir" style="color:#ffffff;text-decoration:none;" dir="ltr">support@parsaaghayi.ir</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
+6
View File
@@ -2,6 +2,7 @@
namespace Tests\Feature;
use App\Mail\ContactMessageConfirmed;
use App\Mail\ContactMessageReceived;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -35,6 +36,11 @@ class ContactMessageTest extends TestCase
&& $mail->hasTo('support@parsaaghayi.ir')
&& $mail->hasTo('parsa.aghaee@gmail.com');
});
Mail::assertSent(ContactMessageConfirmed::class, function (ContactMessageConfirmed $mail) {
return $mail->contactMessage->email === 'ali@example.com'
&& $mail->hasTo('ali@example.com');
});
}
public function test_the_public_form_rejects_invalid_payloads(): void