0

I want to dynamically create EML files and send them to the client, which would open Outlook (corporate network thus Outlook will be present).

So far, Outlook will open, but the entire $test string will be featured in the body and will not populate the subject.

I'm probably missing something in the formatting of the string for it to be interpreted correctly by Outlook?

$test = 'MIME-Version: 1.0

Subject: EMAIL_SUBJECT

Content-Type: multipart/mixed; boundary="080107000800000609090108"

This is a message with multiple parts in MIME format.

--080107000800000609090108

Content-Type: text/html

EMAIL_BODY

--080107000800000609090108';
// send to browser
header('Content-Description: File Transfer');
// handled by default e-mail client
header('Content-Type: message/rfc822');
header('Content-Disposition: inline; filename="template.eml"');
header('Cache-Control: private');
echo $test;
exit;

Edit #1

Sample that works as intended. Plus, found a ton of examples here: https://github.com/mikel/mail/tree/master/spec/fixtures/emails/plain_emails

$test = 'MIME-Version: 1.0
Subject: Testing, 1 2 and 3
Content-Type: text/html

Content here

';
// send to browser
header('Content-Description: File Transfer');
// handled by default e-mail client
header('Content-Type: message/rfc822');
header('Content-Disposition: inline; filename="template.eml"');
header('Cache-Control: private');
echo $test;
exit;
TechFanDan
  • 3,329
  • 6
  • 46
  • 89
  • You'll want to look up correct format for an email message. Headers are not double spaced for a start. – miken32 Apr 25 '22 at 20:15
  • Does this answer your question? [PHP library to generate EML email files?](https://stackoverflow.com/questions/8776481/php-library-to-generate-eml-email-files) – cetver Apr 25 '22 at 20:43
  • @cetver I think I should be able to generate these manually, without a library. I may not be respecting the proper formatting at this moment. The link seems to use an IMAP functionality which seems to require IMAP connectivity, which I don't/can't have. I really need to generate these manually. – TechFanDan Apr 26 '22 at 14:20
  • @miken32 double spaced? I thought there was only the requirement to have a single line. – TechFanDan Apr 26 '22 at 14:21
  • @miken32 in the link provided by another user, one of the answer seem to not have any spacing between the headers. – TechFanDan Apr 26 '22 at 14:22
  • 1
    The headers in your example code above are double spaced. That's not correct. – miken32 Apr 26 '22 at 14:34
  • @miken32, correct! I played around with it and found something that works. – TechFanDan Apr 26 '22 at 16:40

0 Answers0