Skip Navigation

[Gelöst] Create Contact Form with Variable Recipient E-Mail Address

This support ticket is created vor 3 Jahre, 4 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. 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: Africa/Casablanca (GMT+00:00)

Author
Artikel
#1874913
variable-recipient.PNG

I have a custom post type called "Positions" that includes name, e-mail address, etc. I would like to create a form that sends an e-mail to the e-mail address in the Position post type. To do this, I created a second post type called "Messages" but cannot figure out how to pass the e-mail address from the Position into the recipient field of the form. Here is the shortcode that contains the e-mail address:

[types field='position-e-mail' output='raw'][/types]

In the attached screenshot, you can see what I am attempting to do, but it does not work. Is there a better way to accomplish this? I prefer whatever solution we use to avoid making the e-mail address visible in the HTML code on the front end. Thanks in advance for any help

- Aaron

#1875091

Hello, unfortunately the "To" field in the notification settings will not support shortcodes, so you'll need a different approach. If you don't want to include the email address directly in the Form field values, the most viable solution here is to use the Forms notification API cred_notification_recipients to programmatically assign notification recipients on-the-fly: https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

I'm not sure from your description how Positions and Messages are connected, but I assume there some type of Post Relationship involved here. Maybe Positions is the parent and Messages is the child in a O2M relationship? If so, then you can refer to the solution in another ticket here with example code:
https://toolset.com/forums/topic/send-notification-to-recipient-email-defined-in-parent-post-custom-field/

I can help you set up any Toolset APIs you need help with, just let me know if you get stuck somewhere or if you don't have experience with custom code.

#1876243

Hi Christian,

Thanks for the response. I had not set up the Messages post type as a child of Positions, but I can see the logic in doing so. Can you tell me if it is possible to hide the Messages children from the edit Position screen in the admin page? I'd prefer people using the system not have visibility to all messages related to a Position.

- Aaron

#1876349

Yes, that is possible if you use Toolset Access to restrict permissions to the Message post type for specific User roles. This may also remove the Message post type menu item for those Users. So it depends on how strictly you want to enforce this in wp-admin.

#1880941

Sorry for not responding. We had a major snowstorm and have been snowed in for a couple days. Just replying to keep this topic open. Thanks again for your help and I'll pick this back up in the next couple days!

#1881541

No problem, standing by.

#1886217

Hi Christian,

The code you referenced worked beautifully for sending to the e-mail address associated with the parent post type. Can you refresh my memory on how to use a form field to set the "from" name and e-mail address? Thanks - hope you have a great holiday weekend.

- Aaron

#1886803

Jamal
Supporter

Languages: Englisch (English ) Französisch (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Aaron, Christian is on vacation for a couple of days, I'll try my best to help based on what understood.
However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. If you would need further assistance with my suggestion below, please open a new ticket.

I understood that you want to customize the "from" name and email to let the recipient click on "Reply to" and get the correct email, right? If that's the case, you can use the cred_mail_header to customize any headers of the email object.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header

Check this example in another ticket https://toolset.com/forums/topic/emails-from-a-toolset-form-needs-to-reply-to-the-person-who-submitted-it/#post-1457297

#1888155

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.