Before Send Service
public function onBeforeQuickContactServiceSend(int $id_service, string &$subject, string &$content, bool &$is_html, array &$sender, array &$recipients, JModelVAP $model) : bool
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
- $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 theemail
of the customer. In case the mail is configured to send messages only by a specific domain, than it is appropriate to alter theemail
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.
Return Value
Boolean. True to send the message, false to deny it.
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 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.7).
* @param array &$recipients A list of recipient e-mails (added @since 1.7).
* @param JModel $model The current model (added @since 1.7).
*
* @return boolean True to send the message, false to deny it.
*/
public function onBeforeQuickContactServiceSend($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 true;
}
Changelog
Version | Description |
---|---|
1.7 | Added $sender , $recipients and $model arguments.Accepted a return value to abort the sending process. |
1.6 | Introduced. |