Skip Navigation

[Resolved] syntax for notification email to BCC

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.28 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by Waqar 1 year, 12 months ago.

Assisted by: Waqar.

Author
Posts
#2483255
Screenshot.jpg

For years I have been sending email notifications to the post user and to my admin email from a specific form - but recently, the email has been rejected with this message:

This message is not RFC 5322 compliant, the issue is: 550-5.7.1 duplicate To headers.

To I'm trying to change the "send email notification to specific email address" line in the form be to a BCC instead of a TO in the hopes it will fix this issue.

But I'm not clear on the syntax for that line of the form. The info bubble says:

Additional notification recipients
You can enter additional recipients as:
email
name
to/cc/bcc: name

But I'm not sure how to translate that into the syntax for the single line of text I can enter. I have tried:
bcc: info@writingmusicaltheatre.com
(as you can see in the attached screenshot) - but this doesn't seem to work.

Can you help me to know the correct syntax to set up a BCC to that email?

Thanks.

Elise
NMI

#2483911

Hi Elise,

Thank you for contacting us and I'd be happy to assist.

I've performed some tests on my website, following the same 'bcc' format for the notification and it was delivered correctly each time.

Are you having this issue with any particular email address or email service provider?

regards,
Waqar

#2484013

The error message I quoted above has been coming with my OLD syntax - which was to simply put the email address in that line of the form:

info@writingmusicaltheatre.com

The error seems to happen when notifications are sent to a post author who has a gmail.com address - their email does not get delivered because the email as has two "To" headers - one to their gmail address, and the other one to info@writingmusicaltheatre.com

I am trying to avoid that by using a bcc but I don't think I have the syntax right to change the message from a "To" to a "Bcc".

If you look at my screenshot above, I've put in the address as:

"bcc: info@writingmusicaltheatre.com" - but this is NOT sending a BCC

Is that the right syntax?

Elise

#2484021

I just tried changing the format - so that my form notification has the box ticked for "Send email to the post author" (who, in this case, has a gmail address); and in the line for "Send notification to a specific email address" I have written "info@writingmusicaltheatre.com WMT bcc: WMT" - which follows the syntax recommended by the info bubble which says:
You can enter additional recipients as:
email
name
to/cc/bcc: name

This set up resulted in NO email coming to me as a BCC, and the same error message (about duplicate "TO" headers" being returned about the email that was supposed to go to the post author.

NEXT - I put it back to what I had originally (which was to send to the post author, and to send to the specific email address "info@writingmusicaltheatre.com"):

When set up that way, I DO get a copy of the email to info@writingmusical.com - but I ALSO get the error message email saying that the email to the post author was rejected due to duplicate "To" headers.

NEXT - I tried continuing to tick the box for "Send email to the post author" - but I also ticked the box for "Send notification to a WordPress user" - and in the drop down, I chose "BCC" and the user "Admin" (which is the info@writingmusicaltheatre.com username).

This time, when I triggered the form, I did NOT receive an email at info@writingmusicaltheatre.com, but I also did not receive an error. (I will need to check in with my gmail user to see if she got the notification this time or not).

I'm now at a loss for how to get the email notification to come to me (username admin and email info@writingmusicaltheatre.com) AND go to the post author without causing an error.

Elise

#2484229
screenshot.jpg

Some new information: I now think that it is NOT the BCC that is causing the problem.

I removed the BCC and set up the notification to ONLY go to the post author - and then received the email saying that it had been rejected - but I'm attaching a screenshot of the content of the email that was rejected. You will see that it shows TWO recipients: "Charles" (which is a hyperlink to char@betzfamily.info) and to "char@betzfamily.info" - which means that, for some reason, the post notification is sending the email to two versions of the same email - so that must be the source of the duplicate "To" headers.

Why would it be doing that, when all I have ticked is "Send notification to the post author" - so why is the email going to that email address (char@betzfamily.info) TWICE?

Elise

#2485059

Thank you for sharing these updates.

I've performed some further tests and research on this topic and here are my findings:

1. To understand what's normal, here is a quick test. Suppose that we send an email with an 'X' address in the "To" field and a 'Y' address in the "Bcc" field directly from Gmail (or any other email provider).

Both email addresses will receive the email with the 'X' address showing as the 'To' recipient, however, the 'X' address will not see that the copy is also sent to the 'Y' address.

2. When I enable the option "Send notification to the post author" and also enable the option 'Send notification to a specific email address' with 'bcc: test@test.com' format, it works the exact same way.
( screenshot: hidden link )

Note: Capitalization doesn't matter and it works whether you'll use 'Bcc:', 'bcc:' or 'BCC:' etc.

3. Now, as you noted and shown in your latest screenshot if your particular form notification is using the same email address twice in the 'To' field, that is abnormal and will need to be investigated.

Can you please share temporary admin login details, along with a link to the page where this form can be seen?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2485067

You can use this link to get to a form to submit:

hidden link

You want to scroll down to the question "Send notification?" - and then click submit

(but remember that after you've tried it once, it won't trigger an email again unless you first change the field back to "NO EMAIL" and submit, and then change it again back to "Send Evaluation Ready Email"

#2486553

Is anyone working on this? It's been a few days ...

#2486587

Hi Elise,

I apologize for the delay, as we had an unusually busy forum queue over the weekend.

Will continue the testing and share the findings with you, as soon as I can today.

Thank you for your patience.

regards,
Waqar

#2488415

Thank you for waiting.

I've been testing with different email providers with the exact same form notification settings, but couldn't reproduce this issue. This suggests that something specific to your website is involved.

Do I have your permission to download a clone/snapshot of your website? This will allow me to test this on a different server, without affecting the actual website.

#2488881

Absolutely you can do that! Just let me know what you need to make that happen.

#2492147

I've downloaded the website's clone and will be performing some tests on it. Will share the findings, as soon as this testing completes.

Thank you for your patience.

#2496049

Thank you for waiting.

During troubleshooting on your website's clone, I found this custom function in active theme's "functions.php" file:


// Change notification email to evaluator author when submitting assignment
add_filter( 'cred_mail_header', 'notify_grandparent', 10, 4 );
function notify_grandparent( $headers, $formid, $postid, $num_notification ) {
    if($formid != 704 ) return; 
    $num_notification = 0;
    $current_user = get_current_user_id();
    //get the "lab-categories" terms of current "ASSIGNMENTRESULTS" post
    $terms = get_the_terms( $postid, 'lab-categories' );
    $term_slugs = array();
    foreach ( $terms as $key => $taxonomy ){
            $term_slugs[] = $taxonomy->slug ;
    }
    //with above terms, pass it to get_posts function as parameter "tax_query":
    $registrations = get_posts( array(
        'author' => $current_user,
        'post_type' => 'registration',
        'tax_query' => array(
            array(
                'taxonomy' => 'lab-categories',
                'field'    => 'slug',
                'terms'    => $term_slugs,
            ),
        ),
    ));
    
    $evaluator_id = get_post_meta( $registrations[0]->ID, "_wpcf_belongs_evaluator_id", true); // assumes Evaluator CPT slug is 'evaluator'
    $evaluator = get_post( $evaluator_id );
    $evaluator_author = get_user_by( 'ID', $evaluator->post_author );
    $newheaders = array( 'To: ' . $evaluator_author->user_email );
	
    return array_merge($headers, $newheaders);
}

This code is responsible for injecting an extra 'To' header in all email notifications sent for the form "AssignmentResult Edit Form". The issue is fixed if this code is removed or commented out.

The more efficient way to change the 'To' email address programmatically would be to use the "cred_notification_recipients" filter and by proper conditional checks so that it only targets the specific notification in the specific form:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

I hope this helps and please let me know if you need any further assistance with this.

#2496305

Thank you SO MUCH for reminding me about this code I had added to my functions.php (and which has been working fine for years!)

I could use your help, though, in how else I can accomplish this goal.

When the form is submitted, I want an email to go to the author of the form (as a to) and to my admin email (as a bcc) - but I also would like a cc to go to the author of a GRANDPARENT post (as you can see from the code in my functions.php which I know I originally got from someone at Toolset!)

I am at a loss as to how to accomplish this on my own.

Here's how complicated it is:

Each time a student submits an assignment (through this form) - I want to alert the Evaluator of the particular Lab that they are taking. I have several different Lab, all of which have different evaluators.

The AssignmentResult post always belongs to a particular Lab Category - and the person I want to get a CC is the author of the post in Evaluators who has the same Lab Category ...

Pretty complicated, I know ...

Can you help?

#2498081

You can use a slightly updated function, that only adds the extra recipient when the form notification is "Notification when evaluator finishes evaluation".
( this means that the recipients of the other form notification "Notification when student submits assignment" will not be affected by this code )


// Change notification email to evaluator author when submitting assignment
add_filter( 'cred_mail_header', 'notify_grandparent', 10, 5 );
function notify_grandparent( $headers, $formid, $postid, $name_notification, $num_notification ) {
    if ( ($formid == 704) && ($name_notification == 'Notification when evaluator finishes evaluation') )
    {
        $current_user = get_current_user_id();
        //get the "lab-categories" terms of current "ASSIGNMENTRESULTS" post
        $terms = get_the_terms( $postid, 'lab-categories' );
        $term_slugs = array();
        foreach ( $terms as $key => $taxonomy ){
            $term_slugs[] = $taxonomy->slug ;
        }
        //with above terms, pass it to get_posts function as parameter "tax_query":
        $registrations = get_posts( array(
            'author' => $current_user,
            'post_type' => 'registration',
            'tax_query' => array(
                array(
                    'taxonomy' => 'lab-categories',
                    'field'    => 'slug',
                    'terms'    => $term_slugs,
                ),
            ),
        ));
    
        $evaluator_id = get_post_meta( $registrations[0]->ID, "_wpcf_belongs_evaluator_id", true); // assumes Evaluator CPT slug is 'evaluator'
        $evaluator = get_post( $evaluator_id );
        $evaluator_author = get_user_by( 'ID', $evaluator->post_author );
        $newheaders = array( 'To: ' . $evaluator_author->user_email );
        return array_merge($headers, $newheaders);
    } else {
        return $headers;
    }
}

I hope this helps and please let me know how it goes.