PHP Mail

PHP mail functions is one of its core feature. Thus, there is no extra installation required to use PHP mail functions. The only requirement is the installation of a working email system.

PHP mail() function:

PHP mail() function is used to send emails directly from a script.

Syntax:

mail(to,subject,message,headers,parameters);

To:  This is a required parameter which specifies the receiver / receivers of an email in one of the following forms.

  • user1@example.com
  • user1@example.com, user2@example.com
  • User1 <user1@example.com>
  • User1 <user1@example.com>, User2 <user2@example.com>

Subject: This is a required parameter which specifies the subject of a mail to send.

Message: This is a required parameter which specifies the message to be sent.

Headers: This is an optional parameter which specifies any additional headers, including From, Cc, and Bcc.

Parameters: This is an optional parameter which specifies any additional parameter to the sendmail program. When using -f sendmail option, it can be used to set the envelope sender address.

Features of PHP mail() function:

  • Any newline character can not be used in the subject
  • From header must be included in the header parameter while sending a mail.
  • While using additional headers, all the headers should be separated with a CRLF (\r\n).
  • In the message parameter, LF (\n) should be used for line separation.
  • A maximum of 70 characters can be used in the lines of the message.
Please Share