<?php

use api\classes\API_mailsettings;
use bin\php\Classes\mailBuilder;

session_start();
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API_mailsettings.php";
require_once "{$_SERVER['DOCUMENT_ROOT']}/bin/php/Classes/mailBuilder.php";

$API_mailsettings = new API_mailsettings();

if ($API_mailsettings->request_method === 'POST') {
    # Send a test email to an address

    $API_mailsettings->checkPermissions('admin-mailsettings', 'RO');

    $requiredFields = [
        'mail_to' => ['type' => 'email'],
    ];

    $API_mailsettings->validateData($requiredFields);

    # Send the test email
    $mailBuilder = new mailBuilder();
    $API_mailsettings->testSendMail($mailBuilder);

    $API_mailsettings->apiOutput(200, ['success' => 'The test email was sent.']);
}


