A message with an attachment nests one multipart inside another. The outer multipart/mixed holds the body and each file, and the body is the multipart/alternative of 4.19.2. Images referenced from the HTML as cid: URLs add a multipart/related layer between the two.

Each part has its own headers, a blank line, then content. SMTP carries short 7-bit lines, so a file is Base64-encoded in 76-character lines (RFC 2045) with chunk_split(base64_encode($bytes)), and Content-Disposition: attachment offers it as a download. Base64 adds a third, so link large files instead. 4.19.5 shows the real headers a library writes.