namespace WPForms\Emails;
use WPForms\Emails\Templates\General;
* Mailer class to wrap wp_mail().
* Array or comma-separated list of email addresses to send a message.
* CC addresses (comma delimited).
* @param string $key Property name.
* @param string|array $value Property value.
public function __set( string $key, $value ) {
* @param string $key Property name.
public function __get( $key ) {
* Check if a property exists.
* @param string $key Property name.
public function __isset( $key ) {
return isset( $this->key );
* @param string $key Property name.
public function __unset( $key ) {
* Email kill switch if needed.
public function is_email_disabled() {
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return (bool) apply_filters( 'wpforms_emails_mailer_is_email_disabled', false, $this );
* @since 1.6.0 Deprecated param: $linebreaks. This is handled by wpforms_decode_string().
* @param string $input String that may contain tags.
* @param string $context Context of the string.
* @uses wpforms_decode_string()
public function sanitize( $input = '', $context = '' ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
return wpforms_decode_string( $input );
* Get the email from the name.
public function get_from_name() {
$this->from_name = $this->from_name ? $this->sanitize( $this->from_name ) : get_bloginfo( 'name' );
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return apply_filters( 'wpforms_emails_mailer_get_from_name', $this->from_name, $this );
* Get the email from the address.
public function get_from_address() {
$this->from_address = $this->from_address ? $this->sanitize( $this->from_address, 'notification-from' ) : get_option( 'admin_email' );
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return apply_filters( 'wpforms_emails_mailer_get_from_address', $this->from_address, $this );
* Get the email reply to the address.
public function get_reply_to_address() {
if ( empty( $this->reply_to ) || ! is_email( $this->reply_to ) ) {
$this->reply_to = $this->from_address;
$this->reply_to = $this->sanitize( $this->reply_to, 'notification-reply-to' );
if ( empty( $this->reply_to ) || ! is_email( $this->reply_to ) ) {
$this->reply_to = get_option( 'admin_email' );
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return apply_filters( 'wpforms_emails_mailer_get_reply_to_address', $this->reply_to, $this );
* Get the email carbon copy addresses.
* @since 1.8.9 Allow using CC field as an array.
* @return string The email carbon copy addresses.
public function get_cc_address() {
if ( is_array( $this->cc ) ) {
$this->cc = implode( ',', $this->cc );
if ( empty( $this->cc ) ) {
* Filters the email carbon copy addresses.
* @param string $cc Carbon copy addresses.
* @param Mailer $this Mailer instance.
return apply_filters( 'wpforms_emails_mailer_get_cc_address', $this->cc, $this );
$this->cc = $this->sanitize( $this->cc );
$addresses = array_filter( array_map( 'sanitize_email', explode( ',', $this->cc ) ) );
$this->cc = implode( ',', $addresses );
/** This filter is documented in src/Emails/Mailer.php. */
return apply_filters( 'wpforms_emails_mailer_get_cc_address', $this->cc, $this );
* Get the email content type.
* @return string The email content type.
public function get_content_type() {
$is_html = ! Helpers::is_plain_text_template();
if ( ! $this->content_type && $is_html ) {
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
$this->content_type = apply_filters( 'wpforms_emails_mailer_get_content_type_default', 'text/html', $this );
} elseif ( ! $is_html ) {
$this->content_type = 'text/plain';
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return apply_filters( 'wpforms_emails_mailer_get_content_type', $this->content_type, $this );
* @return string The email subject.
private function get_subject() {
if ( empty( $this->subject ) ) {
$this->subject = __( 'New Email Submit', 'wpforms-lite' );
* Filters the email subject.
* @param string $subject Email subject.
* @param Mailer $this Mailer instance.
return apply_filters( 'wpforms_emails_mailer_get_subject', $this->subject, $this );
* @return string The email message.
public function get_message() {
if ( empty( $this->message ) && ! empty( $this->template ) ) {
$this->message = $this->template->get();
* Filters the email message.
* @param string $message Email message.
* @param Mailer $this Mailer instance.
return apply_filters( 'wpforms_emails_mailer_get_message', $this->message, $this );
* @return string The email headers.
public function get_headers() {
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
return apply_filters( 'wpforms_emails_mailer_get_headers', $this->headers, $this );
$this->headers = "From: {$this->get_from_name()} <{$this->get_from_address()}>\r\n";
if ( $this->get_reply_to_address() ) {
$this->headers .= "Reply-To: {$this->get_reply_to_address()}\r\n";
$cc = $this->get_cc_address();
$this->headers .= "Cc: {$cc}\r\n";
$this->headers .= "Content-Type: {$this->get_content_type()}; charset=utf-8\r\n";
* Filters the email headers.
* @param string $headers Email headers.
* @param Mailer $this Mailer instance.
return apply_filters( 'wpforms_emails_mailer_get_headers', $this->headers, $this );
* Get the email attachments.
* @return string|string[]
public function get_attachments() {
if ( $this->attachments === null ) {
* Filters the email attachments.
* @param string|string[] $attachments Array or string with attachment paths.
* @param Mailer $this Mailer instance.
return apply_filters( 'wpforms_emails_mailer_get_attachments', $this->attachments, $this );
* Set an email address to send to.
* @param string|string[] $email Array or comma-separated list of email addresses to send a message.
public function to_email( $email ) {
if ( is_string( $email ) ) {
$email = explode( ',', $email );
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
$this->to_email = apply_filters( 'wpforms_emails_mailer_to_email', $email, $this );
* @param string $subject Email subject.
public function subject( $subject ) {
$subject = $this->sanitize( $subject );
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
$this->subject = apply_filters( 'wpforms_emails_mailer_subject', $subject, $this );
* Set an email message (body).
* @param string $message Email message.
public function message( $message ) {
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
$this->message = apply_filters( 'wpforms_emails_mailer_message', $message, $this );
* @param General $template Email template.
public function template( General $template ) {
// phpcs:ignore WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
$this->template = apply_filters( 'wpforms_emails_mailer_template', $template, $this );
protected function get_errors() {