A simple Laravel-based api service for handling contacts forms. Can handle forms on static web sites, too.
When deploying a web site, you often need to put a contact form somewhere. If you have a static website, there are only a few solutions to handle forms: implementing some sort of server-side logic and or paying for an external service.
If you have a Laravel based server somewhere, you can rely on this simple API for handling contact forms on multiple websites.
This package creates on your Laravel app an easy entry point:
https://yourapp.dev/api/send
where to post all your contact forms. The api will handle the post requests and mail them to selected addresses.
- Server-side validation
- Google reCAPTCHA
- PHP ^7.1.3
- Laravel ^5.5
Open a console window in the root of your Laravel app and install the package using composer:
composer require otrigg/form-mailer
And after that:
composer install
If you can't take advantage of Laravel's auto discovery feature, append
Otrigg\Formmailer\Providers\FormmailerServiceProvider::class,
at the end of the provider array located into config/app.php
Then, publish the configuration file into Laravel's /config
folder:
php artisan vendor:publish
First of all, append to your app's .env
file:
OTRIGG_FORMMAILER_MODE=strict
if you want to authorize only a certain list of websites where the form is hosted, otherwise leave the key empty:
OTRIGG_FORMMAILER_MODE=
Then, edit the published config/formmailer.php
to customize the API.
Insert a list of authorized app IDs that can use the API.
Use random generated alphanumeric strings such as:
'app_id' => [
'th151sAr4nd0m5tr1ng',
],
Insert a list of complete web addresses where the form is hosted:
'referrals' => [
'http://mywebsite.com/myform.html',
],
don't forget to add a slash at the end of nice URLs if your server uses it, i.e.:
'referrals' => [
'http://mywebsite.com/contacts/',
],
Add a list of email addresses where the forms will be sent:
'recipients' => [
'[email protected]',
'[email protected]',
...
],
Customize the rules according to your form fields. Write rules compatible with Laravel's built-in validator:
'rules' => [
'name' => 'required|max:255',
'email' => 'required|email|max:255',
'message' => 'required|max:1024',
'sender' => 'required|email|max:255',
'g-recaptcha-response' => 'required|captcha',
],
sender
refers to the email address that will fill the From:
field. It is required by default.
Warning: Google reCAPTCHA is set as required by default.
If you want to use Google reCAPTCHA don't forget to generate Google reCAPTCHA public and private keys and add them to the .env
file of your Laravel app:
NOCAPTCHA_SITEKEY=google_recaptcha_public_key
NOCAPTCHA_SECRET=google_recaptcha_secret_key
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.