'Send notification mail to user if the user clicks on a button

I'm creating a WordPress website where users can register to join an event, now I want the website to send a notification email as confirmation that the user is registered for the event the user registered for.

I don't have much knowledge of PHP, hence I have the question, what did I forget to do?

<?php
    // If the "Deelnemen" button is used.
    if(isset($_POST['ActButton'.$post_id.''])) {
        if ($exists = $db2->get_var("SHOW TABLES LIKE '".$post_id."'")) {
            // If the tabel exists, insert the user account values into the tabel from the specific activity.
            $insert = $db2->get_var("INSERT INTO `$post_id` (`ID`, `Naam`, `Email`) VALUES ('$user_ID', '$user_name', '$user_email')");
        } else {
        // If tabel doesnt exist yet, create table, then insert user info.
            $createTable = $db2->get_var("CREATE TABLE `$post_id` (
                ID INT(6),
                Naam VARCHAR(30) NOT NULL,
                Email VARCHAR(50)
                )");
            $insert = $db2->get_var("INSERT INTO `$post_id` (`ID`, `Naam`, `Email`) VALUES ('$user_ID', '$user_name', '$user_email')");

            $to = '[email protected]';
            $subject = 'You joined an event';
            $body = 'The email body content';
            $headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <[email protected]>');

            wp_mail( $to, $subject, $body, $headers );
        }
    }
?>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source