# mail() function in PHP

ProgrammingServer Side ProgrammingPHP

The mail() function allows in sending emails directly from a script.

## Syntax

mail(to,sub,msg,headers,parameters);

## Parameters

• to − The receiver / receivers of the email

• sub − The subject of the email.

• msg − The message to be sent.

• headers − The additional headers, such as From, Cc, and Bcc.

• parameters − The additional parameter to the sendmail program. This was added in PHP 4.0.5.

## Return

The mail() function returns the hash value of the address parameter, or FALSE on failure.

## Example

The following is an example to send an email −

<?php
$msg = "This is demo text!";$email_msg = wordwrap($msg,40); mail("demo@example.com","Subject Line",$email_msg);
?>
Published on 21-Feb-2019 17:57:12