vojislavd / livewire-contact-form
Send email from contact form with Livewire
Requires
- livewire/livewire: ^2.7
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-03 17:27:28 UTC
README
This Laravel package add simple Livewire component for contact form, without any styling.
Once package is installed, include Livewire component on page where you want to have contact form, with one of Livewire's method for rendering component.
@livewire('livewireContactForm:contact-form')
or
<livewire:livewireContactForm:contact-form />
Installation
You can install the package via composer:
composer require vojislavd/livewire-contact-form
After that run install command:
php artisan livewirecontactform:install
NOTE
Make sure to include Livewire scripts on every page you plan to use this component.
Add @livewireStyles
inside <head></head>
tag of your HTML page and add @livewireScripts
right before closing <body></body>
tag.
For example:
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Laravel</title> @livewireStyles </head> <body> @livewireScripts </body> </html>
Optionally, you can publish:
Config file again:
php artisan vendor:publish --provider="VojislavD\LivewireContactForm\LivewireContactFormServiceProvider" --tag="config"
Views:
php artisan vendor:publish --provider="VojislavD\LivewireContactForm\LivewireContactFormServiceProvider" --tag="views"
Livewire component:
php artisan vendor:publish --provider="VojislavD\LivewireContactForm\LivewireContactFormServiceProvider" --tag="livewire-component"
Mail:
php artisan vendor:publish --provider="VojislavD\LivewireContactForm\LivewireContactFormServiceProvider" --tag="mail"
This is the contents of the published config file:
return [ 'mail' => [ 'to' => env('CONTACT_FORM_MAIL_TO', null) ] ];
Usage
In .env file define email address where messages from contact form will be sent.
CONTACT_FORM_MAIL_TO=test@example.com
Include component to your HTML page
@livewire('livewireContactForm:contact-form')
To style contact form or email, publish view assets.
Edit Contact Form: resrouces/views/vendor/livewireContactForm/livewire/contact-form.blade.php
Edit Mail: resrouces/views/vendor/livewireContactForm/mail/contact-form-mail.blade.php
Testing
Run the tests with:
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.