Tell us what you are trying to do?
I created a custom type named 'member' with a field named 'mail'. I want to display after the member content (of each member) a form with subject, email of the sender and body inputs. When submitting this form an email will be sent to the member using his e-mail address (field 'mail'). How can i do that ? which component do i need to use ?
What is the link to your site?
hidden link
You'll use CRED ( soon to be called Toolset Forms ) to accomplish this. Here's how I would set this up:
- Create a new post type called "Guest Messages" or something similar. Every time someone submits the form on the front-end of the site, a new post will be created in this post type.
- Create a new custom field group that contains all the fields you want to display in the form - subject, sender email, and message. Assign this field group to the Guest Messages post type.
- Create a CRED form that creates new Guest Messages posts. Auto-generate the form code, then insert a hidden generic field. Set the value of that hidden field to be the "mail" field value of the current Member, like this:
<div style="display:none;">[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']"
}
[/cred_generic_field]</div>
- Insert any other information you want the email to include using Types and Views shortcodes.
- In the CRED notification builder, you select the generic hidden field "member-email" to be used as the "To:" destination email address. You may have to submit the form once on the front-end of the site to see your hidden field appear in the options here.
- Insert this CRED form in the Content Template or Template Layout assigned to the Members post type using the CRED forms shortcodes.
Let me know if you have questions about this. Here are some reference materials:
https://toolset.com/documentation/user-guides/#cred-topics
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/
So i've done what you said :
- The custom post type was created with the required fields
- The CRED form was created with fields and captcha
- The notification was created with the use of the hidden field
The content submitted is stored, but no e-mail sent.
I check if mail are working on my server with the send test e-mail button (bottom of "edit notification" in CRED form), it works (no value from fields but the rest is ok).
Can you help me fix this error ?
The code of my CRED form :
[credform class='cred-form cred-keep-original']
<h1>[wpml-string context="custom-form" name="send_message"]Lui envoyer un message[/wpml-string]</h1>
[cred_field field='form_messages' value='' class='alert alert-warning']
<div style="display:none;">[cred_field field='receiver' post='guest-message' class='' urlparam='' value="[wpv-post-field name='wpcf-firstname' id='$current_page'] [wpv-post-field name='wpcf-name' id='$current_page']"]
[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']",
}
[/cred_generic_field]</div>
<div class="form-group">
<label>[wpml-string context="custom-form" name="sender"]Expéditeur[/wpml-string]</label>
[cred_field field='sender' post='guest-message' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>[wpml-string context="custom-form" name="subject"]Sujet[/wpml-string]</label>
[cred_field field='post_title' post='guest-message' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>[wpml-string context="custom-form" name="message"]Message[/wpml-string]</label>
[cred_field field='post_content' post='guest-message' value='' urlparam='' output='bootstrap']
</div>
[cred_field field='recaptcha' value='' urlparam='' class='form-control' output='bootstrap']
[cred_field field='form_submit' value='Envoi' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[/credform]
The code of the notification :
<p>[types field='sender'][/types] send you this message :</p>
<p>[wpv-post-body view_template="None"]</p>
It would appear that the generic field information is not being set. Please add some debugging code just before the hidden div:
Current post ID: [wpv-post-id id='$current_page']<br />
Mail field: [wpv-post-field name='wpcf-mail' id='$current_page']<br />
... the hidden div code begins here...
The current post ID should match the ID of the post where the wpcf-mail custom field is found. The mail field value should be accurate. Let me know the results.
Is your site using an SMTP mail plugin? Most SMTP plugins modify mail headers in a way that CRED cannot override. As a quick test, please activate a default theme like Twenty Seventeen, then deactivate all plugins except Toolset plugins, and test again. If the problem is still not resolved, please toggle all the email notification editors open in this CRED form editor, and take a full screenshot or a series of screenshots showing all the configurations here for me to review.
I don't use SMTP plugin (only toolset, wpml and db sync). nevertheless i desactived wpml and db sync. sitch to twentyseventeen.
Same result : i.e message stored in data base but no mail. So i send you the screenshoot.
Regards
Can you open the Email Notification and send me a screenshot of that too? It's toggled closed in this screenshot.
Okay I don't see anything obviously wrong here. Let's try a few more troubleshooting steps, and if these don't work I will need to make a clone of your site so I can run tests locally.
- Check the checkbox "Envoyer une notification a une adresse email specifique", and send to a different email address, preferably on a different domain than the Member's email address.
- Check the spam email folders to see if the emails are being blocked by a filter
Let me know if the email is sent to either address.
OK,
If i check the checkbox and specify an address it send the email.
It sends the email to both email addresses, or only the address specified in wp-admin?
What if you copy the Member's email address into the specified address field (send to the same email address twice)?
Sorry i have unchecked the previous checkbox.
So with both checkboxes checked, only the e-mail for the static e-mail was sent.
Regards
Okay at this point I think I need to create a clone of your website so I can run some additional tests. I can install the Duplicator plugin to make that clone. If you approve, please provide login credentials here in the private reply fields.
Okay, I inspected the form on the front-end of the site, and I can see that the generic field was not in the page markup. So I looked at the generic field shortcode and it turns out the trailing comma at the end of the default value definition was causing a problem:
[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']",
}
[/cred_generic_field]
I deleted that trailing comma and now I see the form element appear. Can you test once more and confirm the message is sent to the Member's email?