I'm building a directory of therapists. In the database, there's also an e-mail address field which stores the e-mail address of each therapist. However, that won't be published in the front-end.
Instead, in the single post template, there should be a contact form, which sends and e-mail to the therapist that is currently being viewed.
For that, I somehow need to get the e-mail address from the database and set it as the mailto address in the notification settings.
I already built a contact form post type and set a relation between that and the therapist post type.
Hello. Thank you for contacting the Toolset support.
Do you mean that you want to send email to the email to the e-mail address field of therapist when you submit the contact form? If yes:
- its possible but there is few steps you will have to follow.
If you can share problem URL where I can see the contact form and admin access details. I will review your current setup and guide you with the next steps or possible solution or workaround.
*** 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.
No - you should not as every post relationship have their own advantage and dis-advantage and pros and crons and to access related posts for every relationship is different. So, I suggest you first create a proper one to many post relationship and then we can go with next steps.
I see its staging site and if you do not added any related posts yet you should delete the existing post relationship and then create a new one to many post relationship.
It seems you will have to configure the SMTP for sending emails so I suggest you should install any of the popular SMTP plugin that suits your requirement and try to submit the form and check if you able to get the email.
In addition to that, I would also suggest you should configure your email submit and body as per your requirement with your form:
=> lien caché
I've added the following code to "Custom Code" Section offered by Toolset:
=> lien caché
add_action('cred_save_data', 'func_set_parent_dynaically',10,2);
function func_set_parent_dynaically($post_id, $form_data){
// if a specific form
if ($form_data['id'] == 2077 ){
if (isset($_POST['parent_post_id'])){
$parent_id = $_POST['parent_post_id'];
$parent = toolset_connect_posts( 'verwijslijst-contactformulier', $parent_id, $post_id );
}
}
}
add_filter('cred_notification_recipients', 'func_send_notification_to_parent_email_field', 11, 4);
function func_send_notification_to_parent_email_field($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( $form_id == 2077 ) {
$parent_id = toolset_get_related_post($post_id,'verwijslijst-contactformulier');
// Add email recipient
$mailto = get_post_meta($parent_id, 'wpcf-email', true);
$recipients[] = array(
'to' => 'to',
'address' => $mailto,
'name' => '',
'lastname' => '');
}
return $recipients;
}
I've also installed the mail log plugin and I can see the email is not send but the code successfully fetch the correct parent email address and its trying to send the email but it seems you will have to setup SMTP to send emails. Here is the email log where I can see it's trying to send emails to correct email address:
=> lien caché
Thank you very much. I'm afraid I messed something up though 🙁
This worked, but then I made some changes to the e-mail notification (content, from name, subject) and now it doesn't send the form to the therapist anymore...
I've adjusted the code added with "cred_notification_recipients" hook with "Custom Code" section as given under to send the email to parent post custom email field.