PHP header() gives headers already sent

I had to do it with WordPress’s inbuilt redirect function; wp_redirect();

wp_redirect( $payment->getPaymentUrl() );
exit;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)