
<?php

require_once __DIR__ . '/../config/constants.php';
require_once __DIR__ . '/../vendor/autoload.php';

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

class Email
{

    public static function send($to,$subject,$html)
    {

        $client = new SesClient([

            'version' => 'latest',

            'region' => SES_REGION,

            'credentials' => [

                'key' => SES_ACCESS_KEY,

                'secret' => SES_SECRET_KEY

            ]

        ]);

        try {

            $result = $client->sendEmail([

                'Destination' => [
                    'ToAddresses' => [$to]
                ],

                'Message' => [

                    'Body' => [

                        'Html' => [
                            'Charset' => 'UTF-8',
                            'Data' => $html
                        ]

                    ],

                    'Subject' => [
                        'Charset' => 'UTF-8',
                        'Data' => $subject
                    ]

                ],

                'Source' => SES_FROM_EMAIL

            ]);

            return $result;

        } 
        catch (AwsException $e) {

            Logger::log("email.log",$e->getAwsErrorMessage());

            return false;

        }

    }

}
