arindam/contact-me
A simple Laravel package that adds a “hi-arindam” route after installation. Install via Composer and, if needed, register the service provider manually. No specific PHP or Laravel version dependency claimed.
Installation
composer require dev-arindam-roy/contact-me
Publish the package configuration (if needed):
php artisan vendor:publish --provider="ArindamRoy\ContactMe\ContactMeServiceProvider"
Configuration
Edit config/contact-me.php to set:
First Use Case Add the contact form to a Blade template:
@contactForm
Or use the helper directly:
use ArindamRoy\ContactMe\Facades\ContactMe;
ContactMe::sendContactForm($request);
Blade Integration
@contactForm directive in views for a pre-styled form.'fields' => [
'name' => 'Full Name',
'email' => 'Email Address',
'subject' => 'Subject',
'message' => 'Your Message',
],
API Endpoint Create a route:
Route::post('/contact', [ContactMeController::class, 'store']);
Controller:
use ArindamRoy\ContactMe\Facades\ContactMe;
public function store(Request $request) {
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email',
'message' => 'required|string',
]);
$response = ContactMe::sendContactForm($validated);
return response()->json($response);
}
Custom Validation Extend validation logic via service provider:
ContactMe::extendValidation(function ($validator) {
$validator->after(function ($validator) {
if (str_contains($validator->getData()['message'], 'urgent')) {
$validator->errors()->add('message', 'Urgent messages require admin approval.');
}
});
});
Mail Template Overrides Publish and modify:
php artisan vendor:publish --tag=contact-me-views
Override resources/views/vendor/contact-me/email.blade.php.
Missing Configuration
config/contact-me.php is not published, the package defaults to hardcoded values (e.g., contact@example.com).CSRF Token Mismatch
@contactForm assumes CSRF protection is enabled.@csrf is present in the form or disable CSRF checks in the middleware (not recommended).Recipient Email Validation
if (!filter_var(config('contact-me.recipient_email'), FILTER_VALIDATE_EMAIL)) {
throw new \Exception('Invalid recipient email configured.');
}
Queueing Delays
'queue' => true,
queue table and a queue worker (php artisan queue:work).Log Entries Enable debug mode in config:
'debug' => env('APP_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
Test Mode
Use ContactMe::setTestMode(true) to bypass email sending (useful for unit tests).
Custom Fields Dynamically add fields via config:
'custom_fields' => [
'phone' => 'Phone Number',
'company' => 'Company Name',
],
Access in your controller:
$phone = $request->input('phone', '');
Attachment Support
Extend the sendContactForm method to handle attachments:
public function sendContactForm($data, $attachments = []) {
// Custom logic to process attachments
}
Webhook Integration Trigger actions post-submission via events:
// In ContactMeServiceProvider
ContactMe::afterSend(function ($data) {
// Send Slack notification, log to database, etc.
});
Localization Override labels via language files:
php artisan vendor:publish --tag=contact-me-lang
Edit resources/lang/en/contact-me.php.
How can I help you explore Laravel packages today?