0
votes

I am coding a simple wordpress plugin that has the following action:

add_action( 'wp_mail_failed', 'aetMailError' );

function aetMailError( $wp_error ) {  
    
    update_option('aet_mail_error' , $wp_error->get_error_message( 'wp_mail_failed' ) );
    
}  

But I tried to display the get_option('aet_mail_error') value after the email failed to send but the value is empty..

Can anyone enlighten me if i am saving the error message $wp_error correctly?

Appreciate any help, thank you!

1

1 Answers

0
votes

Try this code. Added priority.

add_action( 'wp_mail_failed', 'onMailError', 10, 1 );
function onMailError( $wp_error ) {
     update_option('aet_mail_error' , json_encode($wp_error,true));
}