<?php

// If necessary, modify the path in the require statement below to refer to the 
// location of your Composer autoload.php file.
// require '/home/rejoiceysn98/api.rejoicelearning.in/vendor/autoload.php';

use Aws\Ses\SesClient;
use Aws\Exception\AwsException;

function mailAWSses($recipient_emails, $sender_email, $subject, $html_message, $errormsg = null)
{
    $recipient_emails = [$recipient_emails]; // adding this to array


    // Create an SesClient. Change the value of the region parameter if you're 
    // using an AWS Region other than US West (Oregon). Change the value of the
    // profile parameter if you want to use a profile in your credentials file
    // other than the default.
    // $SesClient = new SesClient([
    //     'profile' => 'default',
    //     'version' => '2010-12-01',
    //     'region'  => 'us-west-2'
    // ]);

    $SesClient = new SesClient([
        'version' => 'latest',
        'region'  => 'ap-south-1',
        'credentials' => [
            'key'    => 'AKIA45TG5G6V4RE7CS5A',
            'secret' => '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',
        ],
    ]);

    $plaintext_body = '';
    $char_set = 'UTF-8';

    try {
        $result = $SesClient->sendEmail([
            'Destination' => [
                'ToAddresses' => $recipient_emails,
            ],
            'ReplyToAddresses' => [$sender_email],
            'Source' => $sender_email,
            'Message' => [
                'Body' => [
                    'Html' => [
                        'Charset' => $char_set,
                        'Data' => $html_message,
                    ],
                    'Text' => [
                        'Charset' => $char_set,
                        'Data' => $plaintext_body,
                    ],
                ],
                'Subject' => [
                    'Charset' => $char_set,
                    'Data' => $subject,
                ],
            ],
        ]);
        $messageId = $result['MessageId'];
    } catch (AwsException $e) {

        return false;
        // output error message if fails
        echo $e->getMessage();
        echo ("The email was not sent. Error message: " . $e->getAwsErrorMessage() . "\n");
        echo "\n";
    }
    return true;
}
