Home  >  Article  >  Backend Development  >  mail() function in PHP

mail() function in PHP

王林
王林forward
2023-09-12 14:37:061461browse

mail() function in PHP

The mail() function allows sending emails directly from scripts.

Syntax

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

Parameters

  • to - Recipient of the email

  • sub - The subject of the email.
  • msg - The message to send.

  • headers - Additional headers such as From, Cc, and Bcc.

  • Parameters - Additional parameters for the sendmail program. This was added in PHP 4.0.5.

Return

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

Example

The following is an example of sending an email -

<?php
   $msg = "This is demo text!";
   $email_msg = wordwrap($msg,40);
   mail("demo@example.com","Subject Line",$email_msg);
?>

The above is the detailed content of mail() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete