The Contact Form Service handles contact form submissions from the website and sends formatted emails to info@myprk.ca.
- Main service class that handles form submission logic
- Validates and sends emails
- Uses the
ContactFormMailmailable class - Logs errors if email sending fails
- Laravel Mailable class that formats the email
- Queued for background processing
- Sends emails with form data to the configured recipient
- Uses the
emails/contact-form.blade.phptemplate
- Form request validation class
- Validates:
name: Required, string, max 255 charactersemail: Required, valid email format, max 255 charactersmessage: Required, string, 10-5000 characters
- Provides custom error messages
- Updated form with:
- CSRF token protection
- Form POST action to
contact.storeroute - Error display with Bootstrap alerts
- Success/Error message display
- Form field value preservation on validation errors
- Professional email template
- Displays client name, email, and message
- Formatted using Laravel's Mailable markdown feature
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@myprk.ca"
MAIL_FROM_NAME="PRK Immigration"Note: Update these with your actual SMTP credentials.
Route::get('/contact', [HomeController::class, 'contact'])->name('contact');
Route::post('/contact', [HomeController::class, 'storeContact'])->name('contact.store');public function contact()
{
return view('contact');
}
public function storeContact(StoreContactRequest $request)
{
$service = new ContactFormService();
if ($service->handleSubmission($request->validated())) {
return redirect()->route('contact')
->with('success', 'Thank you for your message! We will get back to you soon.');
}
return redirect()->route('contact')
->with('error', 'There was an error sending your message. Please try again.');
}The contact form emails are sent to: info@myprk.ca
To change this, update the CONTACT_EMAIL constant in app/Services/ContactFormService.php:
private const CONTACT_EMAIL = 'your-email@example.com';- User submits the contact form with name, email, and message
- Validation occurs via
StoreContactRequest - ContactFormService receives validated data
- ContactFormMail is queued for sending
- Email template is rendered and sent to
info@myprk.ca - Success/Error message is displayed to the user
✅ Form validation with custom error messages ✅ CSRF token protection ✅ Error display on form ✅ Form field value preservation ✅ Success/failure notifications ✅ Email queuing for background processing ✅ Professional email template ✅ Error logging ✅ Bootstrap-styled form and alerts
- Navigate to
/contact - Fill in the form with:
- Name: Your name
- Email: Your email
- Message: Your message (minimum 10 characters)
- Click "Send"
- Check your inbox at
info@myprk.cafor the email
By default, emails are queued. To process them:
# Process queued jobs synchronously (development)
php artisan queue:work --stop-when-empty
# Or use the database queue driver by updating your .env:
QUEUE_CONNECTION=database- Check
.envmail configuration - Verify SMTP credentials are correct
- Check
storage/logs/laravel.logfor errors - Ensure queue driver is working (if queued)
- Check that all form fields are filled
- Message must be at least 10 characters
- Email must be valid format
- Ensure
resources/views/emails/contact-form.blade.phpexists - Check for syntax errors in the template
- Verify markdown mailable config in mail.php