PHP mail() Function

PHP ezmlm_hash() Function
PHP rewinddir() Function

In this article, you will learn the simple and easy way to send email in PHP. The mail() function in PHP allows you to send emails directly from a script.

what is the syntax of the MAIL() function in php?

toRequired. Specifies the receiver / receivers of the email
subjectRequired. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
messageRequired. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters.Windows note: If a full stop is found on the beginning of a line in the message, it might be removed. To solve this problem, replace the full stop with a double dot:
$txt = str_replace(“\n.”, “\n..”, $txt);
headersOptional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.
parametersOptional. Specifies an additional parameter to the sendmail program (the one defined in the sendmail_path configuration setting). (i.e. this can be used to set the envelope sender address when using sendmail with the -f sendmail option)
PHP mail() method

examples of the MAIL() function

Example 1. In this example, we send a simple email.

// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail("","My subject",$msg);

Example 2. In this example, we send an email with extra headers.

$to = "";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From:" . "\r\n" .

PHP ezmlm_hash() Function
PHP rewinddir() Function
en English
Scroll to Top