• Resolved thedrap

    (@thedrap)


    Hi team! In the past you helped with a function that would send an email to the customer who submitted a review. It works great! I wonder how can I add a BCC email address to monitor the flow since I don’t see you are explicitly using $headers

    The function is coded as follows

    /**
     * Sends an email to the review author when a new review is created.
     *
     * @param \GeminiLabs\SiteReviews\Review $review
     * @return void
     */
    
    add_action('site-reviews/review/created', function ($review) {
    if (empty( $review->email)) {
    return;
    }
    $subject = "ABCD";
    $message = "Thank you so much for your review! Here is what you submitted:\n\n".
       "Rating: {$review->rating}-stars\n".
       "Title: {$review->title}\n".
       "Review: {$review->content}\n\n".
       "Your coupon code is: ABCDEFG"; 
    
    if (!wp_mail($review->email, $subject, $message)) {
    apply_filters('glsr_log', null, 'The notification to <'.$review->email.'> was not sent. Please verify that your server is able to send emails correctly through WordPress.');
    }
    });

    Thanks!!!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    The wp_mail() function allows you to pass in mail headers.

    $to = '[email protected]';
    $subject = 'The subject';
    $message = 'The message';
    $headers = [
        'Bcc: [email protected]',
    ];
    wp_mail($to, $subject, $message, $headers);
    Thread Starter thedrap

    (@thedrap)

    Thanks team.

    Since the original snippet does not pass the variable $headers to the wp_mail function I wasn’t sure how to add it without screwing up the default values.

    So would you mind confirming that the snippet below will add the BCC without breaking the array?

    /**
     * Sends an email to the review author when a new review is created.
     *
     * @param \GeminiLabs\SiteReviews\Review $review
     * @return void
     */
    
    add_action('site-reviews/review/created', function ($review) {
    if (empty( $review->email)) {
    return;
    }
    $subject = "ABCD";
    $headers = [
        'Bcc: [email protected]',
    ];
    $message = "Thank you so much for your review! Here is what you submitted:\n\n".
       "Rating: {$review->rating}-stars\n".
       "Title: {$review->title}\n".
       "Review: {$review->content}\n\n".
       "Your coupon code is: ABCDEFG"; 
    
    if (!wp_mail($review->email, $subject, $message, $headers)) {
    apply_filters('glsr_log', null, 'The notification to <'.$review->email.'> was not sent. Please verify that your server is able to send emails correctly through WordPress.');
    }
    });
    Thread Starter thedrap

    (@thedrap)

    I tested it and the snippet above works like a charm for those who want to use it.

    Thanks!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding BCC to customer notification email’ is closed to new replies.