We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

2.8.20. PHP mail function


This function, with incorrect settings and use, may incorrectly deliver messages to the target mailbox - sent messages may end up in spam or rejected by the recipient's mail server. Recommended to use correct settings or send letters to SMTP.

Function mail allows you to send letters without SMTP-authorization in the mailbox. It is useful for quickly setting up the sending of letters, but at the same time, without specific settings, it can send letters that with high chances will be spam or rejected. The reason for this is the absence of a correct or an indication of the wrong title. FROM upon dispatch, as well as inability to use DKIM.

Pointing heading FROM, it is important to consider which mailbox will be used. Recommended:

  • Or do not specify it in the function itself, but set the correct mailbox in site settings.
  • Or don't install it in site settings, and specify an additional header in the function.

For example, when sending letters with the indication of the header in which the mail.ru domain will be used, the letter will be rejected due to the presence of an SPF record for the mail.ru domain, therefore, only your domain or an existing mailbox should be indicated as a sender.

The mail function has certain parameters for specifying the data of the recipient, sender, letter, and more. An example of using the function:

mail("recipient", "letter subject", "letter body", "additional headers", "Extra options");

All specified function parameters must be specified in double " or single ' quotation marks. An example of using the function is provided in test script... The parameters must match:

  • recipient - the parameter must match standard, cannot contain more than 60 recipients, taking into account those indicated in the header to, Cc, Bcc, and can be specified as:
    • admin@example.com - one recipient.
    • admin@example.com, user@example.com - multiple recipients, separated by commas.
    • Name <admin@example.com> - the name of the recipient and mailbox. Optionally, you can also specify multiple recipients, separated by commas.
  • letter subject - the subject that will be indicated in the letter must correspond standard.
  • body of letter - the text that will be indicated in the letter itself. To indicate the correct body, you need to consider:
    • The body of the letter must be split into lines if it exceeds 70 characters. The string cannot be more than 70 characters. It is convenient to use the function to split text into lines. wordwrap... For example, if the variable $message contains the text of the letter, then you can use it like this:
      wordwrap($message, 70, "\r\n")
    • Splitting lines should be done using CRLF (\r\n).
  • additional headers (optional) - CRLF-separated string (\r\n) headers or an array of strings with specific headers. Frequently cited headings:
    • From - the header, which indicates the sender of the letter. Will create an error when using a specific mailbox in site settings.
    • Reply-To - the address to which replies to the letter will be addressed. It is recommended to use this title instead of From.
    • Content-Type - A MIME header that tells the mailer about the type of data stored in the message. In this header, you can set the used encoding:
      'Content-type: text/html; charset="utf-8"'
    • Cc and Bcc - sending a copy of the message. Cc - copies the message to the addressee, working by analogy with the header To (recipient), but many mail services can use it to separate recipients, so as not to display them a list of who the letter was addressed to. This header for each recipient substitutes the recipient in the header ToThus, each recipient will think that the letter was addressed specifically to him. Bcc - copies the message to the addressee and performs the same function as Cc except that the title is To (recipient) will not be changed and the user to whom the message is addressed will not be displayed in his mailbox in the list of message recipients. This header is dangerous to use and can lead to delivery problems or understanding the reasons for the delivery of the letter to the recipient indicated in it. Important! You cannot specify more than 60 recipients, taking into account those specified in the header To, Cc, Bcc.
  • Extra options (optional parameter) - parameters and keys to use sendmail... Frequently used keys:
    • -Fuser - a key with the name of the sender (not separated by a space).
    • -fuser@example.com - a key with the sender's mailbox (not separated by a space). The parameter will generate an error when using a specific mailbox in site settings.