Cannot modify header information - headers already sent by (PHPMailer SMTP)

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home//public_html/ip/vendor/phpmailer/phpmailer/src/SMTP.php:321)

Filename: helpers/url_helper.php

Line Number: 565

Backtrace:

File: /home//public_html/ip/application/modules/mailer/controllers/Mailer.php
Line: 221
Function: redirect

File: /home//public_html/ip/index.php
Line: 315
Function: require_once

The error “PHP Error Encountered” is not complete.

Before this error, another errorhas occurred, which causes the message “Cannot modify header information - headers already sent by”

  • Check your logs
  • Paste the complete error.

try again, there’s no error in that code that you dumped

try again, there’s no error in that code that you dumped

Check the application/logs of InvoicePlane.
Those logs that you dumped maks no sense.

  • an error occurs
  • another error occurs
  • php doesn’t expect it, so it showz that the header information could not be changed.

Find that first error.
Either in application/logs (hopefully) or in youd server logs.

It’s certainly not those logs that you dumped.
I had to clean it for you

ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_apiKeyPublic”
ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_apiKeyPublic”
ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_clientId”
ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_clientId”
ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_clientSecret”
ERROR - 2025-11-02 16:57:57 → Could not find the language line “online_payment_clientSecret”

ERROR - 2025-11-02 17:08:02 → Severity: Warning → Cannot modify header information - headers already sent by (output started at /home//public_html/psicote.com/ip/vendor/phpmailer/phpmailer/src/SMTP.php:329) /home//public_html/psicote.com/ip/vendor/codeigniter/framework/system/helpers/url_helper.php 565

The real cause is not in the url_helper.php line — that’s just where the error finally appeared.

Here’s how to explain it clearly:


What’s really happening

“Cannot modify header information – headers already sent by (output started at …)”

This means something already sent output to the browser (HTML, spaces, BOM, echo, var_dump, etc.) before PHP tried to send headers (e.g., redirect, cookie, session, etc.).


The real error is

Tell them to look at the first file and line mentioned in the parentheses.

For example:

(output started at /home/.../vendor/phpmailer/phpmailer/src/SMTP.php:329)

That’s the real origin of the problem — not the last file (url_helper.php).

The real error isn’t in url_helper.php — it’s in PHPMailer’s SMTP.php, line 329. That file started sending output (echo, print, or accidental whitespace) before the framework tried to send headers.


How to see the full error

  1. Turn off error suppression:

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    

You can do that by turning on debug in ipconfig.php
This one:

ENABLE_DEBUG

to

ENABLE_DEBUG=true
  1. Check your log file directly (not the truncated message):

    tail -n 50 /path/to/application/logs/log-2025-11-02.php
    
  2. Use ob_start(); early in index.php to buffer output (for debugging only).

  3. If they only paste partial lines, ask them to:

    grep "Cannot modify header information" -A3 -B3 /home/.../logs/log-2025-11-02.php
    

    That prints a few lines before and after the message.


The real problem

“The real problem isn’t in url_helper.php — check the first file and line in parentheses (SMTP.php:329). That’s where output started before headers were sent.”

application/modules/mailer/helpers/phpmailer_helper.php

$mail->isSMTP();
            $mail->SMTPDebug   = env_bool('ENABLE_DEBUG') ? 2 : 0;
            $mail->Debugoutput = env_bool('ENABLE_DEBUG') ? 'echo' : 'error_log';

            // Set the basic properties
            $mail->Host = get_setting('smtp_server_address');
            $mail->Port = get_setting('smtp_port');

            // Is SMTP authentication required?
            if (get_setting('smtp_authentication')) {
                $mail->SMTPAuth = true;

                $decoded = $CI->crypt->decode($CI->mdl_settings->get('smtp_password'));

                $mail->Username = get_setting('smtp_username');
                $mail->Password = $decoded;
            }
$mail->SMTPDebug   = env_bool('ENABLE_DEBUG') ? 2 : 0;

Set that to 3 instead of 2

$mail->Debugoutput = env_bool('ENABLE_DEBUG') ? 'echo' : 'error_log';

Set that to mail.log instead of “echo”

What I have to do?

Read what it says in above post.
If you don’t fully understand it, ask ChatGPT in your own language.

There is an error deep in PHPMailer that is causing this.
Find that error.

  • ENABLE_DEBUG=true in ipconfig.php
  • $mail->SMTPDebug = env_bool('ENABLE_DEBUG') ? 3 : 0;
  • $mail->Debugoutput = env_bool(‘ENABLE_DEBUG’) ? ‘mail.log’ : ‘error_log’; in application/modules/mailer/helpers/phpmailer_helper.php

I have three running program, in one no error in the other two the same errors, but one send just one mail

1 Like

And you have set the debugging information correctly making sure that all errors by phpmailer got caught by mail.log right?

Then you should look at those errors the debugging of phpmailer is giving you.

The error starts here:
vendor/phpmailer/phpmailer/src/SMTP.php:329

And yes, that is not inside InvoicePlane.
That’s why you turn on debugging to get more information from that other script, phpmailer.

You get that information in your mail.log because you’ve set this
$mail->Debugoutput = env_bool(‘ENABLE_DEBUG’) ? ‘mail.log’ : ‘error_log’; in application/modules/mailer/helpers/phpmailer_helper.php

Find out what’s in that log file.

nw when I create new ones I have this error

An uncaught Exception was encountered

Type: SepaQr\Exception

Message: Name of the beneficiary cannot be longer than 70 characters
Filename: /home//public_html/ip/vendor/smhg/sepa-qr-data/src/Data.php

Line Number: 96

Backtrace:

File: /home//public_html/ip/application/libraries/QrCode.php
Line: 46
Function: setName

File: /home//public_html/ip/application/libraries/QrCode.php
Line: 57
Function: paymentData

File: /home//public_html/ip/application/helpers/invoice_helper.php
Line: 125
Function: generate

File: /home//public_html/ip/application/views/invoice_templates/pdf/InvoicePlane.php
Line: 352
Function: invoice_qrcode

Name of the beneficiary cannot be longer than 70 characters

What do you think it means? :thinking:
/application/libraries/QrCode.php#L46
/application/libraries/QrCode.php#L33

I take off the QR code and I am able tò sensi emails but back tobthe precipua error

Please at least try to put it in English.
You have your previous error, i presume.

That means that you look at all the advices that were mentioned there: Cannot modify header information - headers already sent by (PHPMailer SMTP) - #7 by UnderDog