title: Mail dynamically created .ics file attachment unable to open file for reading
body: <p><strong>Environment:</strong><br>
   - Laravel 5.3   </p>
  
  <p><strong>Case:</strong><br>
  Mail about an 'event' including an attachment with an iCalendar file (<code>.ics</code>). The <code>ics</code> file is being generated using <code>PHP</code>.</p>
  
  <p><strong>Problem:</strong><br>
  While sending the mail <em>with</em> the <code>ics</code> file Laravel returns the following error:</p>
  
  <blockquote>
    <p><strong>Swift_IoException</strong> in FileByteStream.php line 144:
    Unable to open file for reading [/storage/app/public/events/eventname.ics]</p>
  </blockquote>
  
  <p>The generated file seems fine while using it without the mail. The event gets added to the calendar so the file is not corrupt. While debugging (<code>dd</code> on the path) the file is getting returned, so folder/access permissions seems fine either.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>// Build mail
  public function build()
  {
      $event = $this-&gt;createEvent($this-&gt;data[2]-&gt;planned_at, $this-&gt;data[2]-&gt;subject, $this-&gt;data[2]-&gt;content);
  
      return $this-&gt;view('emails.template')
          -&gt;from('info@stackoverflow.nl', 'Stackoverflow')-&gt;subject($this-&gt;data[2]-&gt;subject)
          -&gt;with([
              'token' =&gt; $this-&gt;data[0],
              'email' =&gt; $this-&gt;data[1],
              'mail' =&gt; $this-&gt;data[2],
              'sponsors' =&gt; $this-&gt;data[3],
              'name' =&gt; $this-&gt;data[4],
  
          ])
          -&gt;attach(Storage::url('app/public/events/' . $this-&gt;data[2]-&gt;subject . '.ics'), [
              'as' =&gt; $this-&gt;data[2]-&gt;subject . '.ics',
              'mime' =&gt; 'calendar/event',
          ]);
  }
  
  // Build ics file
  static function createEvent($date, $subject, $content)
  {
      $dateTimeArr = explode(' ', $date);
      $newDate = $dateTimeArr[0];
      $dateArr = explode('-', $newDate);
      $newDate = $dateArr[0] . $dateArr[1] . $dateArr[2] . '-' . $dateTimeArr[1];
      $date = substr($newDate, 0, -9);
  
      $startTime = str_replace(":", "", substr($newDate, 9, -3));
  
      $strip = str_replace("\r", "", strip_tags($content));
      $desc = str_replace("\n", "", $strip);
  
      // ICS
      $mail[0] = "BEGIN:VCALENDAR";
      $mail[1] = "-//WEBSITE v1.0//NL";
      $mail[2] = "VERSION:2.0";
      $mail[3] = "METHOD:PUBLISH";
      $mail[4] = "BEGIN:VCALENDAR";
      $mail[5] = "DTSTART:" . $date . "T" . $startTime . "00Z";
      $mail[6] = "DTEND:" . $date . "T" . $startTime . "00Z";
      $mail[7] = "DTSTAMP:" . gmdate('Ymd') . 'T' . gmdate('His') . "Z";
      $mail[8] = "UID:" . md5(uniqid(mt_rand(), true));
      $mail[9] = "ORGANIZER;" . "Stackoverflow";
      $mail[10] = "CREATED:" . $date . "T" . $startTime . "00Z";
      $mail[11] = "DESCRIPTION:" . $desc;
      $mail[12] = "LAST-MODIFIED:" . $date . "T" . $startTime . "00Z";
      $mail[13] = "LOCATION:" . "";
      $mail[14] = "SEQUENCE:0";
      $mail[15] = "STATUS:CONFIRMED";
      $mail[16] = "SUMMARY:" . "";
      $mail[17] = "TRANSP:OPAQUE";
      $mail[18] = "END:VEVENT";
      $mail[19] = "END:VCALENDAR";
  
      //set correct content-type-header
      $filename = $subject . '.ics';
      $mail = implode("\r\n", $mail);
  
      header("text/calendar");
  
      Storage::put('public/events/' . $filename , $mail);
  }
  </code></pre>