email_attachment()

Build an in-memory attachment for smtp_email_send() or record_email_send() — no stored file needed. Attach generated content like calendar invites (make_ical()), vCards, CSV exports, or images from data: URIs.

Syntax

email_attachment(filename, content, content_type?)

Parameters

Name Type Required Description
filename string yes The attachment's file name (e.g. invite.ics).
content string yes Text content, or a data: URI for binary data.
content_type string no MIME type. Defaults to text/plain, or the data: URI's type.

Content starting with data: is unpacked as a data URI (use file_data_uri() or base64-encode binary data yourself: "data:image/png;base64," . $b64). Anything else is attached as literal text — raw base64 is not auto-detected.

To attach files already stored on a record, use the Send Email brick's Attach from file field or record_email_send's attach_field instead.

Returns

An attachment array {filename, content, content_type} — pass it inside the attachments list of an email spec.

Example

$csv = "name,total\n" . $record["title"] . "," . $record["total"];

smtp_email_send("company_smtp", [
    "to"          => $record["email"],
    "subject"     => "Your export",
    "html"        => "<p>Attached.</p>",
    "attachments" => [
        email_attachment("export.csv", $csv, "text/csv"),
        email_attachment("invite.ics", make_ical(["title" => "Review", "start" => "2026-08-01 09:00:00"]), "text/calendar"),
    ],
]);

Example output

["filename" => "export.csv", "content" => "bmFtZSx0b3RhbC...", "content_type" => "text/csv"]