In the end, I created a MIME message using this type of template, where each field is replaced by the variable TEMPLATE_<name> :
From: TEMPLATE_FROM_ADDRESS MIME-Version: 1.0 To: TEMPLATE_TO_ADDRESS Subject: TEMPLATE_SUBJECT Content-Type: multipart/mixed; boundary="080107000800000609090108" This is a message with multiple parts in MIME format. --080107000800000609090108 Content-Type: text/plain TEMPLATE_BODY --080107000800000609090108 Content-Type: application/octet-stream;name="TEMPLATE_ATTACH_FILENAME" Content-Transfer-Encoding: base64 Content-Disposition: attachment;filename="TEMPLATE_ATTACH_FILENAME" TEMPLATE_ATTACH_CONTENT --080107000800000609090108
Then creating the final message is pretty simple using str_replace :
$content = file_get_contents("Template.eml"); $content = str_replace("TEMPLATE_FROM_ADDRESS", $fromEmail, $content); $content = str_replace("TEMPLATE_TO_ADDRESS", $toEmail, $content);
Additional information on attaching a file in this message: The attached name and file extension do not work in * .eml email
this.lau_
source share