-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
PHP Version
8.3
CodeIgniter4 Version
4.6.2
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MySQL 8.0
What happened?
I was working on a function in my controller that previously worked without any issues. The function generates a PDF file and sends it as an attachment using the email library.
When it got to that part, the process failed showing this error:
ErrorException
Undefined array key "cid"
SYSTEMPATH\Email\Email.php at line 1311
1304 }
1305
1306 $name = $attachment['name'][1] ?? basename($attachment['name'][0]);
1307 $body .= '--' . $boundary . $this->newline
1308 . 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline
1309 . 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline
1310 . 'Content-Transfer-Encoding: base64' . $this->newline
1311 . ($attachment['cid'] === '' ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline)
1312 . $this->newline
1313 . $attachment['content'] . $this->newline;
1314 }
1315
1316 // $name won't be set if no attachments were appended,
1317 // and therefore a boundary wouldn't be necessary
1318 if (isset($name)) {
Basically this line:
. ($attachment['cid'] === '' ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline)
My e-mail object is adding the attached file like this:
$email->attach(file_get_contents($filename), 'attachment', 'quote.pdf', 'application/pdf');
Steps to Reproduce
- Make a new
$email = \Config\Services::email();object. - Attach a file using
file_get_contents(...)as an attachment. - Send email.
Expected Output
I expect the e-mail to be sent in a regular manner.
Anything else?
The only thing I can think of is that I updated from PHP 8.1.30 to 8.3.22 just two days ago, so I haven't tested everything yet on 8.3, but this function used to work without any issues on 8.1 and as far as I know the email library hasn't been modified.
I suppose perhaps adding some conditions to the ['cid'] index check, in case it's not set.