How to Send Email from a PHP Script using mail() function.

In this article, I will show you how to send  mail using PHP mail() function in PHP.

PHP mail() function:

The PHP mail() function is used to send emails in php.

Syntax :
mail(string to, string subject, string message, string headers,parameters);

to:  The receiver of the email
subject: The subject of the email.
message: the body of the email.
headers: Additional headers, like From, Cc, and Bcc.


$to = "";//The receiver of the email
$subject = "Test mail"; //The subject of the email.
$body = "Hello!"; //The body of the email.
$from = "";
$headers = "From:" . $from; 
//mail() function
   echo("Message successfully sent!");
  echo("Message delivery failed...");