The email_body function in UserSpice is a custom function that takes in two parameters: $template and $options. The purpose of this function is to generate the HTML body of an email message using a specified template file and a set of optional parameters.
The function first sets the global variables $abs_us_root and $us_url_root to their respective values. It then uses the extract function to extract any key-value pairs from the $options array and create individual variables with their respective values. These variables can be used within the email template file to dynamically generate content based on the provided options.
The function then uses output buffering (ob_start) to capture the HTML output generated by the included template file. The function checks for the existence of the specified template file in two possible locations: the usersc/views directory and the users/views directory. If the file is found in either location, the function includes the file using the require statement.
Finally, the function returns the captured HTML output using ob_get_clean, which ends the output buffering and returns the contents of the buffer as a string.
Here is an example of how to use the email_body function:
Suppose you want to generate an email message using a template file called welcome_email.php located in the usersc/views directory. The template file contains HTML and PHP code to generate the email content dynamically. You can use the email_body function like this:
This will generate the email body HTML using the welcome_email.php template file and the provided $options array. The array contains two key-value pairs: username and email, which can be used within the template file to generate personalized content.