This topic is split from: https://toolset.com/forums/topic/split-how-to-show-the-related-posts-through-view/
Hi Waqar,
What "Notification e-mail trigger" and "Notification e-mail recipients" should we use to send out an automatic email notification to both admin and the vakexpert every time a vakexpert is connected to a post type "introducties"?
I don't think this can be done using a Toolset Form notification. Forms notifications are triggered when the form is submitted. Can I ask how do you connect these posts? Using a relationship form or from the backend?
If you are connecting these posts using the backend, you can create a custom code hooked into the toolset_association_created action. The code needs to build the email and send it using wp_mail
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created
- https://developer.wordpress.org/reference/functions/wp_mail/
Please transfer this issue to Waqar who will be able to answer this better.
Hi,
From the previous ticket, I recall you're using the front-end form to connect "vakexpert" to "introducties".
Can you please share the link to an example page where this form can be seen?
I'll be in a better position to suggest the next steps.
regards,
Waqar
hidden link
The question is how we can send out an automatic email notification to both admin and the vakexpert every time a vakexpert is connected to a post type "introducties"?
Thanks for writing back.
The page link that you've shared is for showing the current user's related "Introducties" posts.
What I wanted to know was about the page where users can connect "Introducties" posts to their "Vakexpert" post.
I see you have a relationship form named "vakspecialisten introducties" in the admin area, but where are you using it on the front-end?
Users don't connect themselves to "introducties" posts, we do that for them (we connect vakexperts in the "introducties" posts directly).
Thank you for clearing that.
Since no front-end Toolset form is involved here, you'll need to add a custom function that uses "toolset_association_created" hook and the "wp_mail" function, to send an email message.
(the same as Jamal suggested in his first reply in this thread)
If you are connecting these posts using the backend, you can create a custom code hooked into the toolset_association_created action. The code needs to build the email and send it using wp_mail
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created
- https://developer.wordpress.org/reference/functions/wp_mail/
Example:
add_action( 'toolset_association_created', 'send_mail_after_akexpert_introductie_created', 10, 5 );
function send_mail_after_akexpert_introductie_created( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
// only if the relationship is "vakexpert-introductie"
if( $association_slug =='vakexpert-introductie' ) {
$to = 'abc@xyz.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
// send email
wp_mail( $to, $subject, $body, $headers );
}
}
Feel free to customize the snippet as needed and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
Hi Waqar,
Is it possible that the snippet includes a typo? "akexpert" instead of "vakexpert".
I assume this snippet should be added to Toolset's settings - "custom code"?
Can you please include below mail subject and body with apropriate merge tags to the snippet:
Subject:
Betr./ landman® | Introductie geactiveerd.
Body:
Beste ("vakexpert" first name),
De introductie is op landman® geactiveerd.
U kunt de hidden link">projectmarktspeler nu uitnodigen om in contact te komen.
Nog vragen?
hidden link">Stuur ons een mail, laat online een bericht of vind antwoorden in hidden link">ons helpcenter.
Met vriendelijke groeten,
landman®
hidden link
hello@landman.re
32 14 75 24 42
Ontvang het aanbod van landman® als eerste. hidden link">Word gratis lid van landman® community, het besloten platform van landman® waar de niet-publiek te koop aangeboden woningen en gronden in primeur worden aangekondigd.
Thanks for writing back.
Yes, there was a typo, but it doesn't affect the functionality of the snippet, since it was just a function's name. Important point is that the function name used in line #1 should match the function definition in line #2.
That code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
I'd like to remind you that the support that we provide over the Toolset forum is limited to the usage of Toolset's features, options, and functions.
( ref: https://toolset.com/toolset-support-policy/ )
For general PHP code customization, you can either consult a specialist community forum ( like https://stackoverflow.com/questions/tagged/php ) or hire a professional ( https://toolset.com/contractors/ ).
I hope you'll understand.
Hi Waqar,
Off course I understand but you know better than anyone else that we cannot hire a professional to customize a snippet.
By means of a gesture and exception, can you please send the custom code?
A small thing for you to do, a big deal for us!
Thanks.
Here is the updated code snippet, with the example subject and the message body:
add_action( 'toolset_association_created', 'send_mail_after_vakexpert_introductie_created', 10, 5 );
function send_mail_after_vakexpert_introductie_created( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
// only if the relationship is "vakexpert-introductie"
if( $association_slug =='vakexpert-introductie' ) {
$to = 'abc@xyz.com';
$subject = 'Betr./ landman® | Introductie geactiveerd.';
ob_start();
?>
Beste ("vakexpert" first name),
De introductie is op landman® geactiveerd.
U kunt de <a href="<em><u>hidden link</u></em>">projectmarktspeler nu uitnodigen</a> om in contact te komen.
Nog vragen?
<a href="<em><u>hidden link</u></em>">Stuur ons een mail</a>, laat online een bericht of vind antwoorden in <a href="<em><u>hidden link</u></em>">ons helpcenter</a>.
Met vriendelijke groeten,
landman®
<em><u>hidden link</u></em>
hello@landman.re
32 14 75 24 42
Ontvang het aanbod van landman® als eerste. <a href="<em><u>hidden link</u></em>">Word gratis lid van landman® community</a>, het besloten platform van landman® waar de niet-publiek te koop aangeboden woningen en gronden in primeur worden aangekondigd.
<?php
$body = ob_get_clean();
$headers = array('Content-Type: text/html; charset=UTF-8');
// send email
wp_mail( $to, $subject, apply_filters( 'the_content', $body ), $headers );
}
}
I hope this helps.
Waqar,
I assume the snippet code is not correct. Is this due to $to = 'abc@xyz.com'?
We receive below notification email when we connect a "vakexpert to a "introductie".
I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster. If you do so, please include this problem report. You can delete your own text from the attached returned message.
The mail system
<abc@xyz.com>:
Yes, your understanding is correct and that email address was just used in the snippet as an example.
Have you tested it with some actual email address?
The mail notification should be sent "automatically" to both admin (hello@landman.re) and the email address of the vakexpert that's being connected Waqar.