buchin/sendfox-integration

A Laravel package for integrating with the SendFox API.
5,671
Install
composer require buchin/sendfox-integration
Latest Version:v0.1.2
PHP:>=8.0
License:MIT
Last Updated:Apr 4, 2025
Links: GitHub  ·  Packagist
Maintainer: buchin

SendFox Integration Package

This package provides a simple integration with the SendFox API for Laravel applications. It allows you to create contacts using the SendFox API.

Installation

  1. Add the package to your Laravel project:

    composer require buchin/sendfox-integration
    
  2. Publish the configuration file:

    php artisan vendor:publish --tag=config
    
  3. Add the required environment variables to your .env file:

    SENDFOX_TOKEN=your_sendfox_api_token
    SENDFOX_URL=https://api.sendfox.com/contacts
    SENDFOX_LIST_ID=your_list_id
    

Usage

Creating a Contact

You can use the SendFoxService to create a contact:

use Buchin\SendFoxIntegration\SendFoxService;

$service = new SendFoxService();

$user = (object) [
    'email' => 'test@example.com',
    'first_name' => 'Test',
    'last_name' => 'User',
];

$response = $service->createContact($user);

if ($response->successful()) {
    echo "Contact created successfully!";
} else {
    echo "Failed to create contact.";
}

Automatically Sending User to SendFox on Creation

You can use Laravel's model events to automatically send a user to SendFox when a user is created. For example, in your User model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Buchin\SendFoxIntegration\SendFoxService;

class User extends Model
{
    protected static function booted()
    {
        static::created(function ($user) {
            $service = new SendFoxService();

            $nameParts = explode(' ', $user->name, 2);
            $firstName = $nameParts[0] ?? '';
            $lastName = $nameParts[1] ?? '';

            $response = $service->createContact((object) [
                'email' => $user->email,
                'first_name' => $firstName,
                'last_name' => $lastName,
            ]);

            if ($response->successful()) {
                Log::info('Contact created successfully in SendFox.');
            } else {
                Log::error('Failed to create contact in SendFox.', $response->json());
            }
        });
    }
}

Testing

The package includes its own tests. To run the tests, navigate to the package directory and run:

php artisan test packages/SendFoxIntegration/tests

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

License

This package is open-sourced software licensed under the MIT license.

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444