PHP code example of locomotivemtl / charcoal-contrib-communicator

1. Go to this page and download the library: Download locomotivemtl/charcoal-contrib-communicator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

locomotivemtl / charcoal-contrib-communicator example snippets


/**
 * @var \Charcoal\Communicator\Communicator $communicator
 * @var \App\Model\Contact\Entry            $entry
 */

$formData = [
    'full_name'     => $entry['full_name'],
    'business_name' => $entry['business_name'],
    'email_address' => $entry['email_address'],
    'category'      => transform($entry['category_id'], function ($categoryId) {
        // Fetch name of Category object from Category ID.
    }),
    'message'       => $entry['message'],
];

$communicator->setFormData($formData);

$communicator->setTo([
    'email' => $entry['email_address'],
    'name'  => $entry['full_name'],
]);

$emailData = [
    'template_data' => [
        'entry'        => $formData,
        'charcoal_url' => build_admin_url('object/edit', [
            'obj_type' => Entry::objType(),
            'obj_id'   => $entry['id'],
        ]),
    ],
];

/** @var bool */
$sent = $communicator->send('contact', 'user', $emailData);