Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
redcap_email
(REDCap >= 9.5.0)
redcap_email — Allows REDCap's normal email-sending process to be intercepted or manipulated for custom purposes.
Description
boolean redcap_email ( string $to, string $from, string $subject, string $message, string $cc = NULL, string $bcc = NULL, string $fromName = NULL, array $attachments = NULL )
Allows REDCap's normal email-sending process to be intercepted or have the email parameters manipulated prior to sending. The parameters passed into this hook function are the exact same ones utilized by the REDCap::email() method.
Location of Execution
The function is executed just before the send() function is called inside the REDCap::email() method and equivalently just before the send() function in REDCap's Message class.
Parameters
to
The email addresses of all the recipients of the email (separated by semicolons).
from
The email address of the sender of the email.
subject
The email subject.
message
The email body.
cc
The email addresses of all the CC'd recipients of the email (separated by semicolons).
bcc
The email addresses of all the BCC'd recipients of the email (separated by semicolons).
fromName
The email display name of the sender of the email.
attachments
An array of one or more file attachments, in which the array keys will represent the file name as seen in the email client and the corresponding array values will represent the full file path of the attachment file on the REDCap server.
Return Values
To prevent REDCap from sending the email normally after this hook is executed, your hook function should return FALSE or 0. If it returns anything else (or returns nothing), it will continue to send the email using the normal internal methods.
Examples
Example #1:
An illustration of how to manipulate the metadata or data used to generate the PDF.
function redcap_email($to, $from, $subject, $message, $cc, $bcc, $fromName, $attachments)
{
    // You may want to send out emails via an alternative method or configuration,
    // OR maybe change something in a particular email based on some decision logic.

    // If this hook function returns FALSE or 0, that will prevent REDCap's email function from sending the email using the normal method.
    // If anything other than FALSE or 0 is returned (including not returning anything), REDCap will proceed with sending the email as usual.
    return TRUE;
}
Example #2:
A much more manageable way to perform project-specific operations for many projects at once is to create a directory structure where each project has its own subdirectory under the main Hooks directory (e.g., named "redcap/hooks/pid{$project_id}/redcap_survey_page.php"). This allows the code for each project to be sandboxed and separated and also makes it more manageable to utilize other files (e.g., PHP, HTML, CSS, and/or JavaScript files) that you can keep in the project's subdirectory (i.e., "pid{$project_id}") in the Hooks folder. Then the designated project handler PHP script can utilize any of the parameters passed in the function to perform actions specific to each project. NOTE: This example assumes that the "hooks" sub-directory is located in the same directory as the PHP file containing the Hook functions.
function redcap_email($to, $from, $subject, $message, $cc, $bcc, $fromName, $attachments)
{
    // Use the email values passed into this hook function to send an email using an alternative configuration.
    // If the sender's address is a Gmail address, then use Gmail SMTP server to send it instead of using our SMTP server defined in PHP.INI.
    if (stristr($from, '@gmail.com') !== false) {
        // Use Gmail SMTP configuration, etc.

        // Return false to prevent REDCap from sending out the email a second time
        return FALSE;
    }
    return TRUE;
}
REDCap 14.9.1 - © 2024 Vanderbilt University