Skip Navigation

[Resolved] Using CRED field value in Email Notification headers (From Name)

This thread is resolved. Here is a description of the problem and solution.

Problem:

I need to be able to dynamically change From Name of email notification. Customer fills his name in CRED form and it should become From Name of email notification.

Solution:

There isn't such a built-in feature within Toolset Forms plugin, it needs custom codes, you can use filter hook "cred_mail_header" to trigger a custom PHP function, and change the mail from name to what you want. For example:

https://toolset.com/forums/topic/using-cred-field-value-in-email-notification-headers-from-name/#post-1289267

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header

This support ticket is created 4 years, 9 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.

Our next available supporter will start replying to tickets in about 0.21 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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by andreyD-2 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1288233
fromemail.PNG

I need to be able to dynamically change From Name of email notification. Customer fills his name in CRED form and it should become From Name of email notification.

Tried to use the shortcode, but it didn't work:
[types field='customer-name'][/types]

#1288321

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin.

And even you can setup custom codes to change the "Notification e-mail from" as custom field value, it will conduct other problem, for example:

spoofing of email addresses
hidden link

Your user will be able to use other people's email address to send the emails, so I don't think it is practical.

#1289031
fromemail2.PNG

I need to be clear: it's not about changing From Email, which may lead to email spoofing. All I need to be able to do is to change From Name with custom field value.

This feature is widely used in other popular and secure form plugins and it would be good to see it in Toolset as well. Which is not harmful or dangerous practice at all. Here is an example from RSForms Pro, which I use for my Joomla clients:

#1289267

Sorry for the misunderstand, but same as above, there isn't such a built-in feature within Toolset Forms plugin, it needs custom codes, you can use filter hook "cred_mail_header" to trigger a custom PHP function, and change the mail from name to what you want. For example:

there is a Toolset form(ID: 123) sending the email notification, and you are going to change the email from name to custom field "customer-name", this custom field is created with Types plugin.

You can try these custom codes:

function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
    if ($formid==123 && $notification_number==0) {
		add_filter('wp_mail_from_name', 'mail_from_name_func', 11, 1);
    }
    return $headers;
}
add_filter('cred_mail_header', 'customise_cred_notifications', 999, 5);

function mail_from_name_func($name){
	$name = get_post_meta(get_the_ID(), 'wpcf-customer-name', true);
	$name = sanitize_text_field($name);
	return $name;
}
#1289885

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.