PHP program to send a text e-mail message

Here, we are going to learn how to send a text e-mail message in PHP?
Submitted by Nidhi, on November 22, 2020

Here, we will demonstrate how we can send a text email message using the PHP program.

Program/Source Code:

The source code to send a text e-mail message is given below. The given program is compiled and executed successfully.

//PHP program to send a text message using e-mail.
ini_set("sendmail_from", "[email protected]");

$header = "From:[email protected] \r\n";
$to = "[email protected]";
$sub = "Subject of the mail";
$msg = "Hello message from email";

$isSuccess = mail($to, $sub, $msg, $header);

if ($isSuccess == true)
    printf("Email send successfully");
    printf("Email sending failed");


If you pass the correct e-mail addresses then 
it will print a "Email send successfully" message on the webpage.


In the above program, we created local variables that are initialized with the following values:

  1. From email address
  2. To email address
  3. Header
  4. Subject
  5. Message

$isSuccess = mail ($to,$sub,$msg,$header);

Here, we used the mail() method, which is used to send a text email message and return the boolean value true or false. The mail() message returns true if the email sends successfully otherwise it returns false.

More PHP Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.