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.
FROM, it is important to consider which mailbox will be used. Recommended:
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
Bcc, and can be specified as:
email@example.com- one recipient.
firstname.lastname@example.org, email@example.com- multiple recipients, separated by commas.
Name <firstname.lastname@example.org>- 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:
$messagecontains the text of the letter, then you can use it like this:
wordwrap($message, 70, "\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
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"'
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
Ccexcept 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
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).
-email@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.