English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Quick Contact  >  Before Send Service

apply_filters( 'vikappointments_before_quick_contact_service_send', bool $send, int $id_service, string &$subject, string &$content, bool &$is_html, array &$sender, array &$recipients, JModelVAP $model )

Fires while before sending an e-mail to the administrators through the Quick Contact feature of a service.


Description

Trigger event to allow the plugins to manipulate quick contact messages for the administrators about specific services.

It is possible to throw an exception to avoid sending the e-mail. The exception text will be used as error message.

This hook can be used, in example, to ban certain e-mail/IP addresses or to forward the same message to several recipients.


Parameters

$send

(bool)  True to send the message, false to deny it.

$id_service

(int)  The ID of the service to notify.

&$subject

(string)  The subject of the e-mail, by default equals to "New Quick Contact for {service}".

&$content

(string)  The content of the e-mail, which is equals to the message wrote by the customer.

&$is_html

(bool)  True in case the content of the e-mail includes HTML tags (always false by default). Useful in case a plugin needs to include HTML tags to the body.

&$sender

(array)  An associative array containing the name and the email of the customer. In case the mail is configured to send messages only by a specific domain, than it is appropriate to alter the email attribute and to include the mail address of the customer within the body.

&$recipients

(array)  An array containing all the mail addresses to notify. By default, the array contains all the addresses specified by the Admin Mail setting.

$model

(JModelVAP)  The model responsible of sending the e-mail.


Example

/**
 * Trigger event to allow the plugins to manipulate quick contact messages for the
 * administrators. It is possible to throw an exception to avoid sending the message.
 * The exception text will be used as error message.
 *
 * @param  boolean  $send         False to prevent e-mail sending (added @since 1.2).
 * @param  integer  $id_service   The service ID.
 * @param  string   &$subject     The e-mail subject.
 * @param  string   &$content     The e-mail content (the customer message). 
 * @param  boolean  &$is_html     True if the e-mail should support HTML tags.
 * @param  string   &$sender      The e-mail sender details (added @since 1.2). 
 * @param  array    &$recipients  A list of recipient e-mails (added @since 1.2).
 * @param  JModel   $model        The current model (added @since 1.2).
 */
add_filter('vikappointments_before_quick_contact_service_send', function($send, $id_service, &$subject, &$content, &$is_html, &$sender, &$recipients, $model)
{
    // include customer details at the beginning of the body
    $content = sprintf("E-mail sent by %s (%s)\n\n", $sender['name'], $sender['email']) . $content;

    // overwrite sender details
    $sender['email'] = 'info@mydomain.com';

    // instead of sending the e-mail to the administrators, send it to all the employees
    // assigned to the specified service
    $recipients = JModelVAP::getInstance('service')->getEmployees($id_service, $strict = true);

    // map the recipients to take only the e-mail of the employees
    $recipients = array_map(function($e)
    {
        return $e->email;
    }, $recipients);

    // get rid of empty records
    $recipients = array_values(array_filter($recipients));

    return $send;
}, 10, 8);

Changelog

Version Description
1.2 Switched from do_action_ref_array to apply_filters_ref_array to accept a return value, which will be used to allow/deny the e-mail sending.
Added $sender, $recipients and $model arguments.
1.0 Introduced.
Last Update: 2021-08-05
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information