
- 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() 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() function accepts three string values representing to address, subject, and message body as parameters and sends the given message.
Syntax
imap_mail ($to, $subject, $message [,$additional_headers, $cc, $bcc, $rpat]);
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
to (Mandatory) This is a string value representing the senders address. |
2 |
subject (Mandatory) This is a string value representing the subject of the mail. |
3 |
message (Mandatory) This is a string value representing the mail body. |
4 |
additional_headers (Optional) This is a string value representing the additional headers. |
5 |
cc (Optional) This is a string value representing the cc address. |
6 |
bcc (Optional) This is a string value representing the bcc address. |
7 |
rpath (Optional) This is a string value representing the return path upon the delivery failure. |
Return Values
This function returns a Boolean value which is TRUE in case of success and FALSE in case of a failure.
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() function −
<html> <body> <?php $to_address = "sender@test.com"; $from_address = "from@test.com"; $subject = "Test_subject"; //Sending a mail $res = imap_mail($to_address, $from_address, $subject); if($res){ print("Mail sent successfully"); }else{ print("Error Occurred"); } ?> </body> </html>
Output
This will generate the following output −
Mail sent successfully
Example
Following is an example of the above function with the optional parameters −
<html> <body> <?php $to_address = "senders_address@test.com"; $from_address = "from_address@test.com"; $subject = "Test_subject"; $cc = "cc_addressc@test.com"; $bcc = "bcc_addressc@test.com"; $rpath = "return_path"; //Sending a mail $res = imap_mail($to_address, $from_address, $subject, $cc, $bcc, $rpath); if($res){ print("Mail sent successfully"); } else { print("Error Occurred"); } ?> </body> </html>
Output
This will generate the following output −
Mail sent successfully