
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
PHP - imap_mail_compose() Function
PHP−IMAP functions helps you to access email accounts, IMAP stands for Internet Mail Access Protocol using these functions you can also work with NNTP, POP3 protocols and local mailbox access methods.
The imap_mail_compose() function accepts two arrays containing header fields and indexed array of bodies as parameters and creates a MIME message.
Syntax
imap_mail_compose($envelope, $body);
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
envelope (Mandatory) This is an array of headers with the following keys: remail, return_path, date, from, reply_to, in_reply_to, subject, to, cc, bcc, message_id and custom_headers. |
2 |
body (Mandatory) This is an array representing the message body with the following keys: type, encoding, charset, type.parameters, subtype, id, description, disposition.type, disposition, contents.data, lines, bytes and md5. |
Return Values
This function returns a string value representing MIME message.
PHP Version
This function was first introduced in PHP Version 4 and works in all the later versions.
Example
Following example demonstrates the usage of the imap_mail_compose() function −
<html> <body> <?php $envelope["from"]= "sender@test.com"; $envelope["to"] = "reciever1@test.com"; $envelope["cc"] = "reciever2@test.com"; $mail_part1["type"] = TYPEMULTIPART; $mail_part1["subtype"] = "mixed"; $mail_part2["type"] = TYPETEXT; $mail_part2["subtype"] = "plain"; $mail_part2["description"] = "test_desc"; $mail_part2["contents.data"] = "sample contents \n\n\n\t"; $body[1] = $mail_part1; $body[2] = $mail_part2; print( imap_mail_compose($envelope, $body)); ?> </body> </html>
Output
This generates the following output −
From: sender@test.com To: reciever1@test.com cc: reciever2@test.com MIME-Version: 1.0 Content-Type: MULTIPART/mixed; BOUNDARY="15319133-10280-1603871611=:4416" −−15319133-10280−1603871611=:4416 Content-Type: TEXT/plain; CHARSET=US-ASCII Content−Description: test_desc sample contents −−15319133-10280-1603871611=:4416−−