yf_mail_driver_mandrill class

Fileplugins/email/classes/mail/yf_mail_driver_mandrill.class.php
Use_class('mail_driver_mandrill', 'classes/mail/')
Extendsyf_mail_driver

Public properties

A site sets them in its config with $PROJECT_CONF['mail_driver_mandrill']['NAME'] = ...;

PropertyDefaultDescription
$PARENT null
$key
string
null The Mandrill API key.

Public methods 3

send

public function send(array $params = [], &$error_message = '')

https://mandrillapp.com/api/docs/messages.php.html.

  • $params array
    public function send(array $params = [], &$error_message = '')
    {
        $mail = null;
        require_php_lib('mandrill');

        $mail = null;
        $result = null;
        try {
            $message = [
                'html' => $params['html'],
                'text' => $params['text'],
                'subject' => $params['subject'],
                'from_email' => $params['email_from'],
                'from_name' => $params['name_from'],
                'headers' => ['Reply-To' => ($params['reply_to'] ?? null) ?: $params['from']],
            ];
            if (is_array($params['email_to'])) {
                foreach ($params['email_to'] as $name => $email) {
                    $message['to'][] = [
                        'email' => $email,
                        'name' => $name,
                        'type' => 'to',
                    ];
                }
            } else {
                $message['to'][] = [
                    'email' => $params['email_to'],
                    'name' => $params['name_to'],
                    'type' => 'to',
                ];
            }
            if ($this->PARENT->ALLOW_ATTACHMENTS) {
                foreach ((array) $params['attaches'] as $name => $file) {
                    $file_name = is_string($name) ? $name : '';
                    $message['attachments'][] = [
                        'type' => mime_content_type($file),
                        'name' => $file_name,
                        'content' => file_get_contents($file),
                    ];
                }
            }
            $async = false;

            $mandrill = new Mandrill($this->key);
            $result = $mandrill->messages->send($message, $async = true, $params['mandrill_ip_pool'], $params['mandrill_send_at']);
            // Example response: $result = [
            //		[
            //			[email] => [email protected]
            //			[status] => sent
            //			[reject_reason] => hard-bounce
            //			[_id] => abc123abc123abc123abc123abc123
            //		]
            //	]
        } catch (Mandrill_Error $e) {
            $error_message = 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
        }
        if (($error_message ?? null) && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
            trigger_error($error_message, E_USER_WARNING);
        }
        if (is_callable($params['on_after_send'])) {
            $callback = $params['on_after_send'];
            $callback($mail, $params, $result, $error_message, $this->PARENT);
        }
        $this->PARENT->_last_error_message = $error_message;
        return $result ? $result['status'] == 'sent' : false;
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        return main()->extend_call($this, $name, $args);
    }

_init

public function _init()
    public function _init()
    {
        $this->PARENT = _class('send_mail');
    }