mail() function in PHP


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);
?>

Updated on: 30-Jul-2019

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements