So I want to BCC all outgoing emails from my wordpress site to two static, hard coded email addresses.
I went to the pluggable.php file and hard coded the BCC headers to the wp_mail() function like this:
function wp_mail( $to, $subject, $message, $headers = ['Bcc: [email protected]', "bcc: [email protected]"], $attachments = array() ) {
But nothing seems to be happening.
What am I missing?
Please do not edit core WordPress files!
Instead, use the relevant hook like
wp_mail
in your case.Here's an example and this code would be added into the theme functions file, or you can add it as a Must Use plugin:
PS: If you added that as a Must Use plugin, don't forget to add the
<?php
at the top.And BTW, just to explain the "nothing seems to be happening", it's because the
$headers
(fourth parameter) value there can be overridden when the function is called, e.g.wp_mail( '[email protected]', 'test', 'test', [ 'From: [email protected]' ] )
— the$headers
is set, hence the default value is not used.So I hope this answer helps, and keep in mind, never edit any core WordPress files! First, because in many WordPress functions (and templates as well) there are hooks that you can use to modify the function/template output, and secondly, your edits will be gone when WordPress is updated.