: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Log given email errors.
* @param array $errors Errors to log.
protected function log_errors( $errors ) {
if ( empty( $errors ) || ! \is_array( $errors ) ) {
foreach ( $errors as $error ) {
'to_email' => $this->to_email,
'subject' => $this->subject,
'message' => \wp_trim_words( $this->get_message() ),
if ( ! \did_action( 'init' ) && ! \did_action( 'admin_init' ) ) {
\_doing_it_wrong( __FUNCTION__, \esc_html__( 'You cannot send emails with WPForms\Emails\Mailer until init/admin_init has been reached.', 'wpforms-lite' ), null );
// Don't send anything if emails have been disabled.
if ( $this->is_email_disabled() ) {
$errors = $this->get_errors();
$this->log_errors( $errors );
* Add filters / actions before the email is sent.
public function send_before() {
do_action( 'wpforms_emails_mailer_send_before', $this );
add_filter( 'wp_mail_from', [ $this, 'get_from_address' ] );
add_filter( 'wp_mail_from_name', [ $this, 'get_from_name' ] );
add_filter( 'wp_mail_content_type', [ $this, 'get_content_type' ] );
* Remove filters / actions after the email is sent.
public function send_after() {
do_action( 'wpforms_emails_mailer_send_after', $this );
remove_filter( 'wp_mail_from', [ $this, 'get_from_address' ] );
remove_filter( 'wp_mail_from_name', [ $this, 'get_from_name' ] );
remove_filter( 'wp_mail_content_type', [ $this, 'get_content_type' ] );