mail

FunctionParams and return types changed in PHP 8.0

Send mail.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

mail Function synopsis

mail(
    string $to,
    string $subject,
    string $message,
    array|string $additional_headers = [],
    string $additional_params = ""
  ): bool

Parameters

$to

Typestring

Receiver, or receivers of the mail.

$subject

Typestring

Subject of the email to be sent.

$message

Typestring

Message to be sent.

$additional_headers

OptionalTypearray|stringDefault value[]

string or array to be inserted at the end of the email header.

$additional_params

OptionalTypestringDefault value""

The $additional_params parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

Return value

Typebool

Returns true if the mail was successfully accepted for delivery, false otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Changes to the mail Function

PHP 8.0

  • Return type added: bool
  • Parameter type added for parameter #1 ($to): string
  • Parameter type added for parameter #2 ($subject): string
  • Parameter type added for parameter #3 ($message): string
  • Parameter type added for parameter #4 ($additional_headers): array|string
  • Parameter default value added for position #4 ($additional_headers): []
  • Parameter name of parameter #5 changed: $additional_parameters to $additional_params
  • Parameter type added for parameter #5 ($additional_params): string
  • Parameter default value added for position #5 ($additional_params): ""
  mail(
-     $to,
+     string $to,
-     $subject,
+     string $subject,
-     $message,
+     string $message,
-     $additional_headers,
+     array|string $additional_headers = [],
-     $additional_parameters
+     string $additional_params = ""
-   )
+   ): bool

mail Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes