Elementor does not run PHP directly inside the editor, so you cannot paste PHP into an HTML widget and expect it to work. If a component needs PHP, you add it to WordPress instead.
Use a snippets plugin like Code Snippets, add your PHP there, and activate it. This is the safest way because it is easy to disable if something breaks.
Add the code to your theme files, usually in functions.php or a custom plugin you maintain. This works, but it is easier to break things if you are not careful, and theme updates can overwrite changes (unless you use a child theme).