0

I'm using the below code to add an Email address to the CC field of the 'customer_refunded_order' and 'customer_partially_refunded_order' Email in WooCommerce.

But eventhough I see the CC header information in the Email, the Email is not delivered to the CC Email address (also no in spam folder), eventhough it is delivered to the default Email address.

function add_cc_to_certain_emails( $headers, $object ) {

    // email types/objects to add bcc to
    // Comment out what you don't need
    $add_bcc_to = array(
        'customer_refunded_order',
        'customer_partially_refunded_order',
    );

    // Prepare the the data
    $formatted_email = utf8_decode('mrbean@gmail.com');

    // if our email object is in our array
    if ( in_array( $object, $add_bcc_to ) ) {

        // Change our headers
        $headers = array( 
            $headers,
            'Cc: '.$formatted_email ."\r\n",
        );
    }

    return $headers;
}
add_filter( 'woocommerce_email_headers', 'add_cc_to_certain_emails', 10, 2 );

Could anyone please help me with this?

I've already tried disabling all other plugins then WooCommerce and using a default WordPress theme. I also already tried to change the cc Email address to something else then Gmail, but also that doesn't help.

Thanks for your help all!

Nick
  • 82
  • 9
  • `$headers .= 'Cc: '.$formatted_email ."\r\n";` - This will be fine for that as `$headers` is a string – mujuonly May 08 '23 at 12:44
  • Thanks! I know see that the Emailadresses are added to the cc field, but they are not received by my Gmail or Outlook account. How can that be possible? – Nick May 08 '23 at 17:26

1 Answers1

0

The email has one header and a lot of header rows, so do not try to return as an array. Try this:

$headers .= 'Cc: ' . ' <' . $formatted_email . ">\r\n";

Very important details: double quotes for return and newline characters. .= operator is equivalent to $headers = $headers . 'some-string';

I did not try it, but class-wc-email.php contains the same solution.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 15:48
  • Thanks for your reply! I noticed that the issue seems to occure on Gmail only, not on a temporary Email inbox like temp-mail.org. So it seems to have something to do with a spam filter or something like that... Do you have any thoughts on that? – Nick May 08 '23 at 16:07
  • Do not send email directly form the web server. Use SMTP with this plug-in: Easy WP SMTP. If you already use SMTP then check the SPF records in the DNS zone. – István Borsányi May 09 '23 at 08:11