IT & Programming

How to generate .eml email file with php

This script is designed to create .eml file that will be opened with any default email client software like thunderbird or microsoft outlook.

Script

$email='From: FROM_EMAIL_ADDRESS

MIME-Version: 1.0

To: TO_EMAIL_ADDRESS

CC: CC_EMAIL_ADDRESS

BCC: BCC_EMAIL_ADDRESS

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

Content-Type: application/octet-stream;name="EMAIL_ATTACH_FILENAME"

Content-Transfer-Encoding: base64

Content-Disposition: attachment;filename="EMAIL_ATTACH_FILENAME"';

$handle=fopen('email.eml','w');

fwrite($handle, $email);

fclose($handle);

Output

email.eml

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *