How to override the email function by using filters? [closed]
IT Nursery
May 16, 2022
0
Is there a do_action() or an add_filter() that I can implement to use my own send mail function instead of Elegant Theme’s wp_mail() function in their Divi theme?
I want to intercept the Divi emailer function and use my own for a contact us form.
1 Answer 1
If Divi theme uses wp_mail() function (which most likely does), you can use the wp_mail filter to pass your own arguments to the function:
function filter_divi_mail( $args ) {
// Modify the options here
$custom_mail = array(
'to' => $args['to'],
'subject' => $args['subject'],
'message' => $args['message'],
'headers' => $args['headers'],
'attachments' => $args['attachments'],
);
// Return the value to the original function to send the email
return $custom_mail;
}
add_filter( 'wp_mail', 'filter_divi_mail' );