Wednesday, August 31, 2022

[FIXED] How to Create RFC Mail Format with Attachment?

Issue

I have a problem with creating an RFC mail format with attachment. Please help me! Thanks


Solution

Attachments are made in multipart email format. You better use some lib to do it. But if you want to manage it yourself you need to create a document separated by multipart bounaries, that contains files in base64 encoding:

First, email headers:

To: admin@example.com
Subject: hi, admin!
Content-Type: multipart/alternative; boundary="some_random_string"

Than body:

This is a multi-part message in MIME format.
some_random_string
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<p>Email text and image</p>
<img src="cid:attached_image">

some_random_string
Content-Type: image/png;name="some.png"
Content-Transfer-Encoding: base64
Content-ID: <attached_image> //<- this used in CID
Content-Disposition: inline; filename="some.png"
//here goes base64 encoded image.

There are some example function in php.net. Look here in comments.



Answered By - Oroboros102
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.