phpsmtpnewlinemimequoted-printable

CRLF in the quoted-printable MIME message


I have a multipart MIME message where one part looks like

------=_Part_901_990681075.1528833507
Content-Disposition: attachment; filename="metadata.txt"
Content-ID: 3314a2d3-6092-48c3-93d9-a45648b6582b@localhost
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

version: 1.0=0Aid: 13848078-9bc3-4ec1-8cb0-3ee07d74f1cb=0Auser: givenName=
=3DJohn; middleName=3DJacob; surname=3DDoe; dateOfBirth=3D=0A=3D1970-01-01;=
gender=3DM; postalCode=3D12345

but recipient says it is malformed metadata section as the =0A should be replaced with true CRLF.

I know that it is representation of CRLF for quoted-printable encoding but this is not what recipient is expecting.

To create metadata part I have used PHP code:

$sMetadata = "version: 1.0
id: $sTrancasctionId
user: givenName=$sUserFirstName; middleName=$sUserMiddleName; surname=$sUserLastName; dateOfBirth=
=$sUSerDOB; gender=$sUserGender; postalCode=$sUserPostalCode";

and then I'm using existing MailSo framework to add it to existing message object.

Any tips on that matter?


Solution

  • As mentioned in the comments the =0A represents only the linefeed (LF) part of CRLF. So the code is likely stored with Unix newlines which only consists of LF, while MIME representation expects CRLF.

    With this command directly after the $sMetadata line you can convert all the newlines to CRLF:

    $sMetadata = preg_replace('/\R/', "\r\n", $sMetadata);