Welcome Guest, Not a member yet? Register   Sign In
PDF attachment download not working in email in IOS/MAC/APPLE
#1

(This post was last modified: 06-06-2025, 02:25 AM by pratibha.cts.)

Hi
I am sending pdf as attachment in email, it works fine when sending "inline", but I found issue, inline pdf is not working properly in ios/mac/apple. So I tried to send force downloadable attachment, it attaches file and I am able to download file, but it doesn't show file content and shows error "Failed to load PDF document." (https://prnt.sc/x0S_mf47G4c4). File showing corrupted on  ios/mac/apple and gmail also.
I have checked the file path, it's correct and same file works fine in inline mode.
I tried the followings, but doesn't worked
PHP Code:
1. $email->attach($attachment'attachment'basename($attachment), 'application/pdf'); 
PHP Code:
2. $email->attach($attachment'attachment''filename.pdf''application/pdf'); 
PHP Code:
3. $tempPath WRITEPATH 'temp/' uniqid() . '.bin';
copy($attachment$tempPath);
$email->attach($tempPath'attachment''document.pdf''application/octet-stream'); 
I am sending dynamically created pdf, which creates on server, then I send it in email. I also tried putting the static PDF on server, that too doesn't worked.
below is my code to send email, please help to resolve this issue.
PHP Code:
function sendEmail($data = [])
{
    if ($data) {

        $email = \Config\Services::email(true);
        $email->clear(true);

        $email->setFrom($data['fromEmail'], $data['fromName']);
        $email->setTo($data['toEmail']);

        if (isset($data['ccEmail']) && !empty($data['ccEmail'])) {
            $email->setCC($data['ccEmail']);
        }

        if (isset($data['bccEmail']) && !empty($data['bccEmail'])) {
            $email->setBCC($data['bccEmail']);
        }

        $email->setSubject($data['subject']);
        $email->setMessage($data['message']);

        if (isset($data['attachments']) && count($data['attachments']) > 0) {
            foreach ($data['attachments'] as $attachment) {
                $email->attach($attachment);
            }
        }

        $res $email->send();        
        
// $error = $email->printDebugger();

        return $res;
    }


Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB