File: /var/www/html/orbidirectory.com/app/Services/MailchimpService.php
<?php
namespace App\Services;
use MailchimpTransactional\ApiClient;
class MailchimpService
{
protected $client;
/**
* Create a new class instance.
*/
public function __construct()
{
$this->client = new ApiClient;
$this->client->setApiKey(env('MAILCHIMP_API_KEY'));
}
public function sendEmail($to, $subject, $body)
{
$message = [
'from_email' => '[email protected]',
'subject' => $subject,
'html' => $body,
'to' => [
[
'email' => $to,
'type' => 'to'
]
]
];
try {
$response = $this->client->messages->send([
'message' => $message
]);
return $response;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}