imap_mail_compose

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_mail_composeCreate a MIME message based on given envelope and body sections

Description

imap_mail_compose(array $envelope, array $bodies): string|false

Create a MIME message based on the given envelope and bodies sections.

Parameters

envelope

An associative array of header fields. Valid keys are: "remail", "return_path", "date", "from", "reply_to", "in_reply_to", "subject", "to", "cc", "bcc" and "message_id", which set the respective message headers to the given string. To set additional headers, the key "custom_headers" is supported, which expects an array of those headers, e.g. ["User-Agent: My Mail Client"].

bodies

An indexed array of bodies. The first body is the main body of the message; only if it has a type of TYPEMULTIPART, further bodies are processed; these bodies constitute the bodies of the parts.

Body Array Structure
Key Type Description
type int The MIME type. One of TYPETEXT (default), TYPEMULTIPART, TYPEMESSAGE, TYPEAPPLICATION, TYPEAUDIO, TYPEIMAGE, TYPEMODEL or TYPEOTHER.
encoding int The Content-Transfer-Encoding. One of ENC7BIT (default), ENC8BIT, ENCBINARY, ENCBASE64, ENCQUOTEDPRINTABLE or ENCOTHER.
charset string The charset parameter of the MIME type.
type.parameters array An associative array of Content-Type parameter names and their values.
subtype string The MIME subtype, e.g. 'jpeg' for TYPEIMAGE.
id string The Content-ID.
description string The Content-Description.
disposition.type string The Content-Disposition, e.g. 'attachment'.
disposition array An associative array of Content-Disposition parameter names and values.
contents.data string The payload.
lines int The size of the payload in lines.
bytes int The size of the payload in bytes.
md5 string The MD5 checksum of the payload.

Return Values

Returns the MIME message as string, or false on failure.

Examples

Example #1 imap_mail_compose() example

<?php

$envelope
["from"]= "joe@example.com";
$envelope["to"]  = "foo@example.com";
$envelope["cc"]  = "bar@example.com";

$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";

$filename "/tmp/imap.c.gz";
$fp fopen($filename"r");
$contents fread($fpfilesize($filename));
fclose($fp);

$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream";
$part2["description"] = basename($filename);
$part2["contents.data"] = $contents;

$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";

$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;

echo 
nl2br(imap_mail_compose($envelope$body));

?>

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Definition of stored procedures - an introduction

Stored procedures are predefined SQL code blocks that are stored in a database and can be called up as required. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial