Tell us what you are trying to do?
I have two custom post types: 'Nieuwbouwprojecten' (EN = 'projects') and 'Contacten' (EN = 'contacts'). Here are some important custom fields attached to it:
NIEUWBOUWPROJECTEN
- Contact mail company (Email)
CONTACTEN
- First name (Single line)
- Last name (Single line)
- Phone (Phone)
- E-mail address (Email)
- Message (Multiple lines)
Those 2 post types are linked with a one-to-many relationship:
Nieuwbouwprojecten [0 .. 1] << Contacten [*]
I've made a view to show a bunch of 'nieuwbouwprojecten' and a single page to show more info about a single 'nieubouwproject'. Within that single page, there's a post form so you can get in touch with the owner of that project.
The fields in that post form are identical to the custom fields attached to the post type 'contacten'.
When a user send the form, all the data is stored and linked correctly in the database as I expected. So far so good!
THE PROBLEM
When the form is submitted, I want to send an email to the owner of the projects. So I need the value of that "Contact mail company" custom field loaded into 'Send notification to a specific email address'. I've tried a couple of things but none of them are working.
My best attempt: [types field='contact-mail-bedrijf' output='raw'][/types]
See screenshot "contact-email-notification.png"
When I complete the form and send it, no mail goes to the emailaddress. Perhaps I've used a wrong code? Can you help me with this please?
Thanks for your reply! Unfortunately, the custom field is not coming from the form. Note that the posted form data goes into the "Contacten" custom fields. The parent post type ("Nieuwbouwprojecten") single page have that "emailaddress" custom field and holds that form.
Perhaps there's another way to send a notification to that e-mailaddress where I wasn't thinking about?
Given that the page itself holds the email then you can get the email address into the form.
For this you will need to add a generic email field to your form, then for the value of that field you will use the types shortcode that is used generate the output on the page.
Finally save the form and then you should be able to setup the email notifications to be sent based on this field value.
Thanks Shane, you've pointed me in the right direction. I managed to send the email to the right email address!
For others who have the same problem, here's the code I used in my notification mail: