Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Mail System In PHP
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Mail System In PHP

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Mail System In PHP

PHP mail() function is used to send email in PHP. You can send text messages, HTML messages, and attachments with a message using PHP mail() function.

PHP mail() function

Syntax 1

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )  

Syntax 2

mail($to,$subject,$message,$headers,$parameters); 
Parameter Description
to Required. Specifies the receiver/receivers of the email
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
message Required. Defines the message to be sent. Each line should be separated with an LF ( ). Lines should not exceed 70 characters.

Windows note: If a full stop is found at the beginning of a line in the message, it might be removed. To solve this problem, replace the full stop with a double dot:
<?php
$txt = str_replace(" .", " ..", $txt);
?>

headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF ( ).

Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.

parameters Optional. Specifies an additional parameter to the sendmail program (the one defined in the sendmail_path configuration setting). (i.e. this can be used to set the envelope sender address when using sendmail with the -f sendmail option)

Note: Each line of the message should be separated with a CRLF ( ) and lines should not be larger than 70 characters.
$additional_headers (optional): specifies the additional headers such as From, CC, BCC etc. Extra additional headers should also be separated with CRLF ( ).

PHP Mail Example

File Name: php_mailer.php
 

<?php  
   ini_set("sendmail_from", "supprot@easytolearning.com");  
   $to = "easytolearning2@gmail.com";//change receiver address  
   $subject = "This is subject";  
   $message = "This is simple text message.";  
   $header = "From:supprot@easytolearning.com 
";  
   $result = mail ($to,$subject,$message,$header);  
   if( $result == true ){  
      echo "Message sent successfully...";  
   }else{  
      echo "Sorry, unable to send mail...";  
   }  
?>  

If you run this code on the live server, it will send an email to the specified receiver.

PHP Mail: Send HTML Message

To send HTML message, you need to mention Content-type text/html in the message header.

<?php  
   $to = "easytolearning2@gmail.com";//change receiver address  
   $subject = "This is subject";  
   $message = "<h1>This is HTML heading</h1>";  
   $header = "From:support@easytolearning.com 
";  
   $header .= "MIME-Version: 1.0 
";  
   $header .= "Content-type: text/html;charset=UTF-8 
";   
   $result = mail ($to,$subject,$message,$header);    
   if( $result == true ){  
      echo "Message sent successfully...";  
   }else{  
      echo "Sorry, unable to send mail...";  
   }  
?>  
Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
PHP mail() Function How to send an email using PHP Sending Emails using PHP php mail html php mail smtp php send email form php mail function smtp php mail attachment

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.