-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Bug: Email.php inline images fail. #8419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The first parameter is a real filename., not new filename. public function index(): string
{
$email = \Config\Services::email();
$filename = ROOTPATH . 'tests/_support/Images/EXIFsamples/portrait_4.jpg';
$email->attach($filename);
$email->setFrom('[email protected]', 'Your Name');
$email->setTo('[email protected]');
$cid = $email->setAttachmentCID($filename);
$email->setMessage('<img src="cid:' . $cid . '" alt="photo1">');
$email->send(false);
return $email->printDebugger();
}
|
From the documentation: "If you need to use a buffer string instead of a real - physical - file you can use the first parameter as buffer, the third parameter as file name and the fourth parameter as mime-type" Setting the indexes in setAttachmentCID to 1 will fix it but it's not the proper solution. Still working on that. So, try this to see it fail: // Change to your email to test.
$to = '[email protected]';
$email = \Config\Services::email();
$email->attach(base64_decode('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACEFBMVEVHcEz/AAAAAAD/AAD/AACqAAD/AAC/AAD/MwDMMwD/KwDVKwDbJAD/IADjHADmGgDqFQDtJADuIgDvIADwHgDhHgDyGwDkGwDmGgDzGADoIwD0IADrHQDtGwDtGgDuGgDmGQDnIADwHwDoHwDpHgDqHADrIQDsHwDtHgDuHADoHADqIADqHwDwHgDrHgDrHQDsHADsHADqHQDrHADsHwDtHgDpHgDtHQDpHQDpHQDqHADuHgDrHgDrHQDsHADsHADtHwDqHgDqHgDuHQDrHQDrHADsHgDsHQDrHADrHgDrHgDuHQDsHQDrHADuHgDsHgDsHgDsHgDsHQDsHQDtHQDtHgDtHADtHgDrHgDsHQDsHgDsHgDsHgDtHgDtHQDtHQDrHQDtHQDrHQDsHQDrHQDrHQDtHgDrHgDtHQDsHQDsHQDsHQDqHQDrHgDsHQDrHQDrHQDrHQDsHgDsHQDrHQDsHQDsHQDrHQD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Bmi9wL6GuwnD99sH34XgBsDzzx/b0w4IXdceWHl4iW6ftTuTxu1Lr4B+zgC/ANUzlwVxpAXgAAAAAElFTkSuQmCC'),
'inline', 'image001.png', 'image/png');
$cid1 = $email->setAttachmentCID('image001.png');
$subject = 'CodeIgniter 4 Email inline image bug';
$message = 'CI Logo image > <img src="cid:'. $cid1 .'"> < image.';
$email->setTo($to);
$email->setFrom('[email protected]');
$email->setSubject($subject);
$email->setMessage($message);
$email->send(); |
$email->attach($buffer, 'attachment', 'report.pdf', 'application/pdf'); https://codeigniter4.github.io/CodeIgniter4/libraries/email.html#CodeIgniter\Email\Email::attach |
@CleverInsert Please try #8446 |
PHP Version
7.4, 8.0, 8.1, 8.2, 8.3
CodeIgniter4 Version
4.4.1+
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
macOS, Linux
Which server did you use?
apache
Database
No response
What happened?
Inline images for emails show up as attachments, Cid reference is empty.
Steps to Reproduce
Make a new email with
\Config\Services::email();
Attach an image:
$email->attach('image data', 'inline', 'image001.png', 'image/png');
Get the cid for the image;
$email->setAttachmentCID('image001.png');
Add the image to the body:
<img src="cid:'. $cid1 .'">
Send the email.
Expected Output
Email should contain the image inline with no attachment shown.
Anything else?
The problem lies in vendor/codeigniter4/framework/system/Email/Email.php
Method setAttachmentCID references [0] for name of the attachment while it should be [1].
Both
and
have the wrong index.
The array comes from the attach method line 681:
$namesAttached = [$file, $newname];
The text was updated successfully, but these errors were encountered: