binomeway/nova-contact-tool

This package is abandoned and no longer maintained. No replacement package was suggested.

A Laravel Nova tool to configure contact details and send mails based on them.

v1.0.6 2021-08-12 13:47 UTC

This package is auto-updated.

Last update: 2024-07-12 20:04:37 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A package to manage contact information such as: email, phone, socials and forms.

Installation

You can install the package via composer:

composer require binomeway/nova-contact-tool

Install nova-settings

composer require optimistdigital/nova-settings

Add the following line to the boot method within the NovaServiceProvider.php in order to be able to modify contact data withing Nova.

// NovaServiceProvider.php 
public function tools()
{
    return [
        \OptimistDigital\NovaSettings\NovaSettings\NovaSettings::make(),
        \BinomeWay\NovaContactTool\NovaContactTool\NovaContactTool::make(),
    ];
}

You have to publish and run the migrations

php artisan vendor:publish --provider="BinomeWay\NovaContactTool\ToolServiceProvider" --tag="nova-contact-tool-migrations"
php artisan migrate

You can publish the config file with if needed.

php artisan vendor:publish --provider="BinomeWay\NovaContactTool\ToolServiceProvider" --tag="nova-contact-tool-config"

This is the contents of the published config file:

return [
    'default_to' => '',
    'default_subject' => '',
    'save_messages' => true,
    'save_subscribers' => true,
    'priority' => 3,
    'delete_on_unsubscribe' => false,
    'enable_gmail_api' => env('ENABLE_GMAIL_API', false),
];

Usage

Subscribers

Making a new subscriber.

use BinomeWay\NovaContactTool\Facades\Contact;

$subscriber = Contact::subscribe($email, $name, $phone);
use BinomeWay\NovaContactTool\Facades\Contact;

Contact::unsubscribe($subscriber);

Sending Mails

Send emails easy as that.

use BinomeWay\NovaContactTool\Facades\Contact;

Contact::send($message, $subscriber);

Example

use BinomeWay\NovaContactTool\Facades\Contact;
use BinomeWay\NovaContactTool\Models\Subscriber;
// Perform validations
// Create a subscriber
$subscriber = new Subscriber();
// or use the subscribe method
$subscriber = Contact::subscribe($email, $name, $phone);

$message = 'Hello!';
$to = 'hello@binomeway.com'; // Optional

$contact = Contact::send($message, $subscriber, $to);

// Checking if the mail was sent.

if($contact->hasSucceded()){
     flash()->message('success', 'Yay! Email was sent.');
}

if($contact->hasFailed()){
    flash()->message('error', $contact->errorMessage());
}

Sending using Gmail API

First you need to enable the Gmail API features.

ENABLE_GMAIL_API=true

Further, add the credentials in the .env file.

GOOGLE_PROJECT_ID=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=

Or use a JSON credentials file by adding it to the path: storage/gmail/tokens/gmail-json.json

Adding more options

GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true
GOOGLE_ALLOW_JSON_ENCRYPT=true

Next step is to authorize a Gmail Account by using the admin panel.

That's it. Now you can use the same send method, and it will work.

Note: The authorization login won't work on localhost. Gmail doesn't allow local domains

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.