Sends an email through the server's mail program.
Syntax
mail(string $to, string $subject, string $message, array|string $additional_headers = []): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $to | string | The recipient's address. |
| $subject | string | The subject. |
| $message | string | The body. |
| $additional_headers | array|string | Optional. Headers: `From`, `Reply-To`, `Content-Type`. |
Return value
bool`true` if the email was accepted for delivery.
Examples
A simple email:
<?php
// send.php
$sent = mail('anna@example.com', 'Order received', 'Thank you for your order #42.', [
'From' => 'shop@example.com',
'Content-Type' => 'text/plain; charset=utf-8',
]);
echo $sent ? 'Sent' : 'Failed';Notes
true does not mean the email arrived. Real projects send email over SMTP with PHPMailer or Symfony Mailer.
See also
- filter_var — Validates or sanitises a value by a given rule.
- error_log — Writes a message to the error log.
- header — Sends an HTTP response header.
Related recipes
In the tutorial
- Sending email — How to send email from PHP — the mail function, the PHPMailer library and SMTP, HTML emails, attachments and protecting headers.