Skip Navigation

[Resolved] Trouble setting Reply-To on CRED emails

This support ticket is created 3 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 21 replies, has 2 voices.

Last updated by Steve Palm 3 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2146167

I am hopeful you are able to point out the error of my approach, your support has been excellent up to this point. 🙂

** Tell us what you are trying to do?

We have a form for a user to request more information about a listing on the site. We don't want to disclose the email of the listing maintainer, so are using an "information request" form to submit the viewer's contact details to the listing author so they can contact them. I have found information about using the cred_mail_header() hook, but it does not seem to be called.

** Is there any documentation that you are following?

https://toolset.com/forums/topic/setting-from-et-reply-to-fields-with-cred/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header
https://toolset.com/course-lesson/send-notifications-when-someone-submits-the-form/?utm_source=plugin&utm_campaign=forms&utm_medium=gui&utm_term=email-notifications

** Is there a similar example that we can see?

No, as it is only the outbound notification email.

** What is the link to your site?

hidden link

I have put some error_log() statements in the plugin I wrote to hook into the 'cred_mail_header' hook. I see the plugin file is indeed activated and loading, but the error_log() inside the hook function is never called.

The plugin is very simple:

[code]
function cmic_set_replyto_info_request( $headers, $formid, $postid, $notification_name, $notification_number ) {
error_log( "set replyto called" );
if ($formid==3978 && $notification_name=='Information Request') {
$myheaders = array( 'Reply-To: '.$_REQUEST["sender-email"] );
return array_merge($headers, $myheaders);
}
return $headers;
}
add_filter('cred_mail_header', 'cmic_set_replyto_info_request', 10, 5);
[/code]

#2146747

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

That is really strange. That means the hook is not called or something still is missing.

Can you please share problem URL where you added the form as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2146853

Thank you, Minesh. I do not know why the hook is not being called, but hopefully your greater experience will triumph here and find out why. 🙂

You can view the test listing I made and use the Request Information to see the form that is sending the email:

hidden link

#2147417

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can I run few test on the site for which you shared the access details?

#2147799

It is a live public site, but if you make respectful listings and remove them when finished, it would be OK to test. That is why I made the duplicator backup for you, so that you could create a local copy, but I understand the desire to test in-place.

#2149633

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please try to use the following code and check if that helps:

function cmic_set_replyto_info_request( $headers, $formid, $postid, $notification_name, $notification_number ) {
error_log( "set replyto called" );
if ($formid==3978 && $notification_name=='Information Request') {
$myheaders = array( 'Reply-To: '.$_REQUEST["wpcf-sender-email"] );
return array_merge($headers, $myheaders);
}
return $headers;
}
add_filter('cred_mail_header', 'cmic_set_replyto_info_request', 10, 5);
#2149899

I think you missed the most basic point...

As I stated originall, ** the error_log() inside the hook function is never called**. It is even outside the comparison of formid and notification_name, so I would expect to see it logged for every form that sends an email, and yet it is never called at all. If I do put an error_log() in the top level of the plugin code to show that the plugin is loading and active, it does fire.

So for some reason the 'cred_mail_header' filter simply appears to never be called.

#2151035

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked on your install and I do not have access the the theme files. It looks like you added the code you shared to the functions.php file.

Can you please share FTP access details.

I have set the next reply to private which means only you and I have access to it.

#2151041

This is not the case.

The plugin is: cmic-set-inforequest-replyto

That should be in the complete duplicator dump I sent you. All the theme files and everything else should be in there as well. But I provided you the code being used. I have temporarily enabled file editing so you can see on-site data.

#2151047

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

But I will require FTP access details to view/check the logs. Can you please send me FTP access details.

I have set the next reply to private which means only you and I have access to it.

#2151757

Unfortunately, I do not have the ability to easily set up FTP access to the site.

I find it interesting, though, that I received two test emails from you, and both had the Reply-To set, but yet when I just tested it for myself it did not work. What did you do to send those emails?

I have installed a plugin that shows recent error_log() entries on the main WP Dashboard page, will that help?

#2152263

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've changed the code you added to your plugin file as given under:

function cmic_set_replyto_info_request( $headers, $formid, $postid, $notification_name, $notification_number ) {
    error_log( "set replyto called - minesh" );
    if ($formid==3978 && $notification_name=='Information Request') {
        // error_log( "set replyto called: Form: " . $formid . " name: " . $notification_name );
        $myheaders = array( 'Reply-To: '.$_REQUEST["wpcf-sender-email"] );
        return array_merge($headers, $myheaders);
    }
    return $headers;
}
add_filter('cred_mail_header', 'cmic_set_replyto_info_request', 8, 5);

And I can see the error log is logged with the string "set replyto called - minesh".

#2152269

Yes, I see it firing when you tested, but why was it not working before? Do you have an answer? Because the error_log() is the first thing in my version and in yours, but it was not working before. Do you have an answer?

#2152271

Oh, I see, you lowered priority from 10 to 8.

#2152337

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - exactly 🙂

And also changed the following line of code from:

 $myheaders = array( 'Reply-To: '.$_REQUEST["sender-email"] );

To:

 $myheaders = array( 'Reply-To: '.$_REQUEST["wpcf-sender-email"] );