RCP_Emails

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/
The RCP_Emails class handles constructing and sending emails to members and administrators. It can be used by extensions to send emails using the RCP email template.
Sending an email with this class is very simple. There are four steps:

Initialize the class
Set the member_id (important if you want to use template tags showing membership details).
Set the payment_id (optional).
Send the email.

Here’s an example:
$emails = new RCP_Emails();
$emails->member_id = 3; // ID of associated member, if using template tags.
$emails->payment_id = 5; // ID of associated payment ID, if applicable.

$to = ‘[email protected]’; // Email address you want to send the message to.
$subject = ‘Hello’; // Email subject
$message = ‘Your message here.’; // Email message

$emails->send( $to, $subject, $message );

If you want to send attachments along with the email, pass the file paths as a string or array as a fourth parameter:
$emails->send( $to, $subject, $message, $attachments );

Public methods

__set( $key, $value ) – Set a property.

get_from_name() – Get the email from name.

get_from_address() – Get the email from address.

get_content_type() – Get the content type. This will either be ‘text/html’ or ‘text/plain’.

get_headers() – Returns the email headers.

get_templates() – Returns array all available email templates.

get_template() – Returns the ID of the enabled email template.

get_heading() – Returns the header text for the email (specified the email settings).

build_email( $message ) – Build the email by converting to HTML and putting the message inside the template.

send( $to, $subject, $message, $attachments = ” ) – Send the email

send_before() – Adds filters/actions before the email is sent.

send_after() – Removes filters/actions after the email is sent.

text_to_html( $message ) – Converts the provided message to formatted HTML. This turns line breaks into

and
tags.

get_tags() – Retrieves an array of all registered email tags. Each array entry will include the tag name, description, and associated function.

email_tag_exists( $tag ) – Checks if $tag is a registered email tag.

Filters

rcp_emails_from_name – Filters the from name.

rcp_emails_from_address – Filters the from address.

rcp_email_default_content_type – Used for changing the default content type ( ‘text/html’ ).

rcp_email_content_type – Filters the selected content type that will be used for the email.

rcp_email_headers – Filters the headers used for the email.

rcp_email_templates – Used for adding a new template choice to the array of templates.

rcp_email_template – Filters the selected template.

rcp_email_heading – Filters the email heading.

rcp_email_message – Filters the email message.

rcp_email_attachments – Filters the attachments before sending the email.

rcp_email_template_tags – Used for adding a new template tag.

Have more questions?

Submit a request