wp_redirect() doesn’t work

The problem is not what you are doing, but when you are doing it.

When your browser requests a webpage, that webpage arrives with a set of HTTP headers, followed by a HTTP body that contains the HTML. Redirection is done via a HTTP header. The moment you echo, or printf or send any form of HTML, or even blank space PHP will send HTTP headers telling the browser to expect a webpage, then it will start sending the HTTP body. When this happens your opportunity to redirect has gone, and any attempt to send a HTTP header will give you the error in your question.

For this reason, you cannot trigger http redirects in shortcodes, widgets, templates, etc.

Instead, do it earlier, before output begins, preferably in a hook, e.g.

add_action( 'init', 'asmat_maybe_redirect' );
function asmat_maybe_redirect() : void {
    if ( ... ) {
        wp_redirect( 'http://www.my-site.com/my-page/' );

Additionally, if that redirect is to somewhere else on the same site, use wp_safe_redirect instead. But whatever you do, it must happen early before any output occurs.