$report Report payload. * @param string $to Optional override recipient. * @return bool|WP_Error */ public static function send_report( $report, $to = '' ) { $settings = $report['settings']; $to = ! empty( $to ) ? sanitize_email( $to ) : sanitize_email( $settings['client_email'] ); if ( empty( $to ) || ! is_email( $to ) ) { return new WP_Error( 'amar_invalid_email', __( 'Please enter a valid client email address in Settings.', 'agency-maintenance-activity-reports' ) ); } $subject = AMAR_Report::parse_subject( $settings['report_subject'], $report ); $body = AMAR_Report::render_html( $report, true ); $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $from_name = sanitize_text_field( $settings['agency_name'] ); $from_email = sanitize_email( get_option( 'admin_email' ) ); if ( ! empty( $from_name ) && ! empty( $from_email ) && is_email( $from_email ) ) { $headers[] = sprintf( 'From: %s <%s>', $from_name, $from_email ); } $sent = wp_mail( $to, $subject, $body, $headers ); if ( ! $sent ) { return new WP_Error( 'amar_mail_failed', __( 'The report email could not be sent. Check your WordPress mail configuration.', 'agency-maintenance-activity-reports' ) ); } return true; } }