diff --git a/functions.php b/functions.php index b0a092a..e2c15b8 100644 --- a/functions.php +++ b/functions.php @@ -143,8 +143,16 @@ function quiztech_ajax_send_job_invite() { // Generic failure from create_invitation if no WP_Error wp_send_json_error( [ 'message' => esc_html__( 'Failed to create invitation.', 'quiztech' ) ], 500 ); } else { - // Success! $result might contain the token or true - wp_send_json_success( [ 'message' => esc_html__( 'Invitation sent successfully.', 'quiztech' ) ] ); + // Success! $result contains the token. Now send the email. + $token = $result; + $email_sent = $invitations->send_invitation_email( $applicant_email, $token, [ 'job_title' => get_the_title( $job_id ) ] ); + + if ( $email_sent ) { + wp_send_json_success( [ 'message' => esc_html__( 'Invitation sent successfully.', 'quiztech' ) ] ); + } else { + // Invitation created, but email failed. + wp_send_json_error( [ 'message' => esc_html__( 'Invitation created, but the email could not be sent. Please check email settings.', 'quiztech' ) ], 500 ); + } } } catch ( \Exception $e ) { // Catch any unexpected exceptions