How to use conditions in mail body?

I have a form page which will send an email when the form values are submitted to the database for storage.

That Send Mail body code has these 2 lines.

If a “{{$_POST.gender}}” value = “Frau” then only the Div id “conditional2” will be generated in the html and displayed in the email on arrival.

If a “{{$_POST.gender}}” value = “Herr” is detected then the “Frau greeting” is not generated in the body of the email and the “Herr greeting” is the only greeting displayed in the email.

But I don’t know how to write the Conditional code here. I’ve looked at various examples but they don’t seem to match my situation.

Because the Email body is only written into a DMXConnect/API/sendemail.php file I thought I’d have it available in the API send email script.

I want to try this but I don’t know how to express this in Wapplerese. So I am sitting here with just the starting id values “conditional1 & conditional2”

In javascript in multiple conditons I’d sometimes have to also write HIDE conditionals as well to make forms behave.

So by editing the actual Sendemail.php API file where the selected value of “{{$_POST.gender}}” is inserted into the database I hope to find it a little further down in the scope of the send email function.

I would appreciate some expertise here.

Well, just use the ternary operator:

{{$_POST.gender == 'Frau' ? 'Greeting for Frau' : 'Greeting for Herr'}}

You don’t need any conditional regions in the mail body for that.

Teodor, I thank you for that – so the ternary operator means the code looks something like this?

{{$_POST.gender == ‘Frau’ ? '

Sehr geehrte Frau {{$_POST.vorname}} {{$_POST.nachname}}


: ‘<p class=“p1”>Sehr geehrter Herr {{$_POST.vorname}} {{$_POST.nachname}}’
}}

and the logic : means that if the value is NOT ‘Frau’ it will generate the next code past the : without needing the != ‘Frau’ ?

No,
The code looks exactly as i entered it:

{{$_POST.gender == 'Frau' ? 'Sehr geehrte Frau' : 'Sehr geehrter Herr'}} 
{{$_POST.vorname}} {{$_POST.nachname}}

That’s just a standard operator used in the programming languages: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

Oh, okay!
In the first example I only see one line.
In this example I see the other line that makes sense to me.

Thank you, Teodor!

Well my first example shows the greeting only … The post variables for names are always the same, that’s why I did not include them.