# Email tool on IOS (IPad or Iphone) does not open attachment

**URL:** <https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862>\
**Category:** Need Help\
**Tags:** help\
**Created:** [February 12, 2024, 1:59pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862 "2024-02-12T13:59:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![wjcoelho](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wjcoelho](https://discourse.cakephp.org/u/wjcoelho)\
**Post date:** [February 12, 2024, 1:59pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/1 "2024-02-12T13:59:55Z")

</div>

I’m having a problem opening attachments sent on IOS (Ipad and iPhone) by CakePHP 4, the attachment icon appears, but the file does not show.  
Email resent using another tool, the attachment appears to open or view.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [February 12, 2024, 2:18pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/2 "2024-02-12T14:18:19Z")

</div>

If the same E-Mail attachment opens up in e.g. thunderbird or outlook but doesn’t open in Apple Mail (iOS, MacOS etc.) then it’s not a problem of the server framework (CakePHP) to fix this issue.

Besides the fact, that CakePHP’s mail logic is pretty minimal and you should be able to reproduce your problem with a pure PHP mail as well (unless you of course send via SMTP)

---

<div class="post-metadata">

**Author:** ![wjcoelho](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wjcoelho](https://discourse.cakephp.org/u/wjcoelho)\
**Post date:** [February 12, 2024, 2:24pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/3 "2024-02-12T14:24:51Z")

</div>

Thank you for answering me, but the problem is in the cake sending, something must be missing, because sent with pure PHP code doesn’t give me any problems:

in my source with CAKEPHP:

```auto
$email = new Mailer('default');
        $email->setFrom(['no-reply@test.com' => 'test']);
        $email->setTo('contact@test.com');
        $email->setSubject('Test PDF');
        $r = [
            'test.pdf' => [
                'file' => 'test.pdf',
                'mimetype' => 'application/pdf',
                'contentId' => md5((string) time())
            ]
        ];
        $email->setAttachments($r);
        $email->deliver('Test pdf');

```

email source response:

```auto
--rel-46376bdb4daca54b8956b95260cc5646
Content-Disposition: inline; filename="test.pdf"
Content-Type: application/pdf
Content-Transfer-Encoding: base64

![captura-iphone-erro|283x500](upload://jXSEVyiDtQFSNc02v7pQ3nl2fwX.jpeg)

-------------------------------------------------------
in my source mail with pure PHP:

email source response:

```

–==Multipart\_Boundary\_x6e9bd24c753707a5c3196f2d48fdace2x  
Content-Type: application/pdf;  
name=“test-file.pdf”  
Content-Disposition: attachment;  
filename=“test-file.pdf”  
Content-Transfer-Encoding: base64

![captura-iphone-okay](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/e/e743e2b16c248056196a78fca84575fe3e5b4059.jpeg)

code send:

```auto
$name = "Test PDF";
        $email = "test@test.com.br";
        $to = "$name <$email>";
        $from = "Test-PDF ";
        $subject = "Here is your attachment";
        $mainMessage = "Hi, here's the file.";
        $fileatt = "test.pdf"; //file location
        $fileatttype = "application/pdf";
        $fileattname = "test-file.pdf"; //name that you want to use to send or you can use the same name
        $headers = "From: $from";
        // File
        $file = fopen($fileatt, 'rb');
        $data = fread($file, filesize($fileatt));
        fclose($file);
        // This attaches the file
        $semi_rand = md5((string) time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
        $headers .= "\nMIME-Version: 1.0\n" .
                "Content-Type: multipart/mixed;\n" .
                " boundary=\"{$mime_boundary}\"";
        $message = "This is a multi-part message in MIME format.\n\n" .
                "--{$mime_boundary}\n" .
                "Content-Type: text/plain; charset=\"iso-8859-1\n" .
                "Content-Transfer-Encoding: 7bit\n\n" .
                $mainMessage . "\n\n";

        $data = chunk_split(base64_encode($data));
        $message .= "--{$mime_boundary}\n" .
                "Content-Type: {$fileatttype};\n" .
                " name=\"{$fileattname}\"\n" .
                "Content-Disposition: attachment;\n" .
                " filename=\"{$fileattname}\"\n" .
                "Content-Transfer-Encoding: base64\n\n" .
                $data . "\n\n" .
                "--{$mime_boundary}--\n";
        if (mail($to, $subject, $message, $headers)) {
            echo "The email was sent.";
        } else {
            echo "There was an error sending the mail.";
        }

```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 12, 2024, 2:55pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/4 "2024-02-12T14:55:34Z")

</div>

Check the headers and the content of each version carefully, to see where they differ.

---

<div class="post-metadata">

**Author:** ![wjcoelho](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wjcoelho](https://discourse.cakephp.org/u/wjcoelho)\
**Post date:** [February 12, 2024, 3:02pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/5 "2024-02-12T15:02:05Z")

</div>

Above there are two tests:

pure php, the attachment appears on the iPhone  
cakephp 4.1, attachment does not appear on iPhone

Could any of the DEV help me with version 4.1?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 12, 2024, 3:47pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/6 "2024-02-12T15:47:42Z")

</div>

I see your code, but it’s hard to parse through all of that to see what might actually differ in what’s going to the SMTP server. You are the only one that has the ability to look at the end result of what’s being generated, by examining the headers and “view source” of the emails that are actually sent. By comparing the email that works to the email that doesn’t, we can work backwards to determine what aspect of that output is causing the issue, and hence to determine the issue in the code that is responsible for that.

---

<div class="post-metadata">

**Author:** ![thomasg](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thomasg](https://discourse.cakephp.org/u/thomasg)\
**Post date:** [February 13, 2024, 1:36am UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/7 "2024-02-13T01:36:47Z")

</div>

is the filepath correct? file.pdf seem like an odd filepath.

---

<div class="post-metadata">

**Author:** ![wjcoelho](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wjcoelho](https://discourse.cakephp.org/u/wjcoelho)\
**Post date:** [February 14, 2024, 11:24am UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/8 "2024-02-14T11:24:01Z")

</div>

yes, the filepath is correct.  
It’s a small PDF file, written test on it, could someone who has an iPhone do this test and give me feedback if they can send it?  
Or as a solution, you shouldn’t use cakephp to send the file by email and use pure php?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 14, 2024, 3:18pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/9 "2024-02-14T15:18:36Z")

</div>

Lots of people are using Cake for sending email with attachments. If you don’t want to do the debugging work that I’ve already suggested (twice), I can’t help you fix your implementation.

---

<div class="post-metadata">

**Author:** ![wjcoelho](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wjcoelho](https://discourse.cakephp.org/u/wjcoelho)\
**Post date:** [February 16, 2024, 12:52pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/10 "2024-02-16T12:52:24Z")

</div>

cakephp doesn’t work on iphone:

Subject: Test CakePHP - subject  
From: Test CakePHP - name [no-reply@test.com](mailto:no-reply@test.com)  
Date: Fri, 16 Feb 2024 08:46:58 -0300  
Message-ID: [41175aa173d84d59861d769312c3b25b@test.com](mailto:41175aa173d84d59861d769312c3b25b@test.com)  
MIME-Version: 1.0  
Content-Type: multipart/mixed; boundary=“c5ae5d55466fa4bef10247f656ce1a0d”  
Content-Transfer-Encoding: 8bit

–c5ae5d55466fa4bef10247f656ce1a0d  
Content-Type: text/plain; charset=UTF-8  
Content-Transfer-Encoding: 8bit

Test CakePHP - message

–c5ae5d55466fa4bef10247f656ce1a0d  
Content-Disposition: attachment; filename=“test.pdf”  
Content-Type: application/pdf  
Content-Transfer-Encoding: base64

–c5ae5d55466fa4bef10247f656ce1a0d–

==============================================================  
pure working on iphone:

Subject: Test PHP-Pure - subject  
From: Test PHP-Pure - name [no-reply@test.com](mailto:no-reply@test.com)  
MIME-Version: 1.0  
Content-Type: multipart/mixed; boundary=“rel\_31f6dd577335e45ab91de9b89b4fc2f2x”  
Content-Transfer-Encoding: 8bit  
Message-Id: [20240216121344.3290DE0021@test.com](mailto:20240216121344.3290DE0021@test.com)  
Date: Fri, 16 Feb 2024 09:13:44 -0300 (-03)

–rel\_31f6dd577335e45ab91de9b89b4fc2f2x  
Content-Type: multipart/alternative; boundary=“rel\_31f6dd577335e45ab91de9b89b4fc2f2z”

–rel\_31f6dd577335e45ab91de9b89b4fc2f2z  
Content-Type: text/plain; charset=UTF-8  
Content-Transfer-Encoding: 8bit

Test PHP-Pure - message

–rel\_31f6dd577335e45ab91de9b89b4fc2f2z–  
–rel\_31f6dd577335e45ab91de9b89b4fc2f2x  
Content-Disposition: attachment; filename=“test.pdf”;  
Content-Type: application/pdf; name=“test.pdf”;  
Content-Transfer-Encoding: base64

–rel\_31f6dd577335e45ab91de9b89b4fc2f2x–

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 16, 2024, 3:45pm UTC](https://discourse.cakephp.org/t/email-tool-on-ios-ipad-or-iphone-does-not-open-attachment/11862/11 "2024-02-16T15:45:01Z")

</div>

The “pure” output has a `Content-Type: multipart/alternative` line in it, which I don’t see anything about in your code. Is that happening from PHP `mail` function, or do you have a different version of the code generating that?

Anyway, that seems to be the main difference here. Looking at Cake’s code, it seems that this happens only when you send the message in both HTML and text formats. Maybe give that a try and see if it fixes it?
