English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Mail  >  After Send

do_action( 'vikrestaurants_after_send_mail', mixed $result, Mail $mailmixed $transporter, object $options )

Fires after VikRestaurants tried to deliver an e-mail.


Description

It is possible to use this hook to track the stability of the e-mail transporter.

This hook is fired even if the vikrestaurants_before_send_mail thrown an exception.


Parameters

$result

(bool|Exception)  Whether the e-mail was delivered or not. An exception in case of mailing configuration error or whether the vikrestaurants_before_send_mail hook manually thrown it to abort the sending process.

$mail

(Mail)  Encapsulates the e-mail information. This class is part of the E4J\VikRestaurants\Mail namespace.

$transporter

(mixed)  The instance used by the CMS to dispatch e-mail notifications.

$options

(object)  A configuration registry. Only the following attributes are used in this context.

  • silent (bool) - True to ignore any thrown exception and go ahead without breaking the process (false by default).
  • admin (bool) - True to enqueue a system message in case of errors (false by default). Applies only in case of silent delivery.

Example

/**
 * Fires after delivering an e-mail.
 * 
 * @param  mixed   $result       Whether the delivery succeeded or not.
 * @param  Mail    $mail         The e-mail information.
 * @param  mixed   $transporter  The e-mail transporter.
 * @param  object  $options      The configuration registry.
 * 
 * @since  1.3
 */
add_action('vikrestaurants_after_send_mail', function($result, $mail, $transporter, $options) {
    if ($result instanceof Exception) {
        // prevent the system from breaking the whole process
        $options->set('silent', true);

        if (current_user_can('administrator')) {
            // we have an administrator, display the error as system message
            $options->set('admin', true);
        }
    }
}, 10, 4);

Changelog

Version Description
1.3 Introduced.
Last Update: 2023-12-20
Helpful?
See Also: