How do I set WordPress to send 2 different emails based on criteria in the database when someone submits a form?

So what you want to do, assuming I understand correctly, is check if the user already exists in the system. I don’t think using names is a good idea, two people can have identical names. I have two guys with the same first and last name that play on a soccer team with me. Emails are at least unique, so I’d check that.

Once you determine if the person already exists or not and I guess then you’d update their the Attended_Advisory column to ‘Yes’ or true or 1. (I use 1 and 0 for true and false just to keep things as lean as possible.)

Then, when the registration is complete you retrieve the data from the custom table and add the Attended_Advisory value to a variable.

$attended_advisory = the_result_of_the_db_query; //query that retrieves the attended advisory value from the custom table

Next you run a conditional check on that value, something like:

if( empty( $attended_advisory ) || $attended_advisory === 'No' ) :
     /*Send the Email for NO */
     /*This condition checks if the value IS empty OR if it is a No */ 
else :
    /*Send the Email for YES */
    /*This condition checks if the value IS NOT empty AND if it is a Yes */
endif;

You could even add a layer as a just in case:

if( empty( $attended_advisory ) || $attended_advisory === 'No' ) :
   /*Send the Email for NO */
   /*This condition checks if the value IS empty OR if it is a No */
elseif( !empty( $attended_advisory ) && $attended_advisory === 'Yes' ) :
   /*Send the Email for YES
   /*This condition checks if the value IS NOT empty AND if it is a Yes */
else :
   /*Send the Email for NO - a fallback that covers everything else. */
endif;

That’s the logic. You’ll obviously have to modify the above to work with how you have things set up above, but logically this is the process.

tech