<?php

namespace Plainwork\EmailWordPress;

use Plainwork\Email\EmailSender as BaseEmailSender;

final class EmailSender extends BaseEmailSender
{
    public function send(string $to, string $subject, string $message, array $headers = [])
    {
        // add_filter('wp_mail_from', array($this, 'getConfirmationFrom'));
        // add_filter('wp_mail_from_name', array($this, 'getFromName'));

        $res = wp_mail($to, $subject, $message, $headers);

        // remove_filter('wp_mail_from', array($this, 'getConfirmationFrom'));
        // remove_filter('wp_mail_from_name', array($this, 'getFromName'));

        if (!$res) {
            $err = 'Error sending email';
            // global $ts_mail_errors, $phpmailer;
            // if (!isset($ts_mail_errors)) $ts_mail_errors = array();
            // if (isset($phpmailer)) $ts_mail_errors[] = $phpmailer->ErrorInfo;
            // $err = 'Error sending email: ' . join('---', $ts_mail_errors);

            // return $ret->addError($err);
        }

        return $res;
    }
}
