PHP Mail Functions

Beginner
3 min read
Updated: Nov 2026
2 function guides
Function index

About This Index

This page is the PHP Mail Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn how mail() hands a message to the mail system, what headers do, and how to avoid header injection on /php/mail. Use this page when you need a specific function such as mail() or ezmlm_hash().

Beginner path.

Start with mail()—then read ezmlm_hash() only if you work with an EZMLM mailing list on an older PHP version.

true does not mean delivered.

mail() returns true when the local mail system accepts the message. It needs sendmail_path (Linux, macOS) or SMTP settings (Windows) in php.ini to send anything. ezmlm_hash() was removed in PHP 8.0.

How to Call a PHP Mail Function

Both helpers are global functions—call them directly. mail() takes the recipient, subject, message, and optional headers, and returns a bool:

PHP
$accepted = mail(
    '[email protected]',
    'Order 1042 shipped',
    'Your order has shipped.',
    ['From' => '[email protected]', 'Reply-To' => '[email protected]']
);
var_dump($accepted);                               // bool: accepted, not delivered

// PHP 7 and earlier only (removed in PHP 8.0)
// echo ezmlm_hash('[email protected]');            // int from 0 to 52

PHP Mail Functions Table

All function guides in this PHP tutorial series (2 tutorials in 2 categories).

Send mail

1 function

Send a plain-text email from PHP. The function returns true when the mail system accepts the message, which is not the same as delivered.

FunctionDescriptionTutorial
mail()Send an email message with a subject, body, and optional headers.Try it

EZMLM helper

1 function

A small helper for EZMLM mailing lists. It was removed in PHP 8.0, so it applies to older PHP versions only.

FunctionDescriptionTutorial
ezmlm_hash()Get the EZMLM hash of an email address for subscriber file names.Try it

Frequently Asked Questions

The mail extension has two functions. mail() sends an email message through the mail system that php.ini points to, and ezmlm_hash() returns the hash used by EZMLM mailing lists to name a subscriber file.
The Mail page teaches the ideas: how mail() works, headers such as From and Reply-To, why true does not mean delivered, php.ini settings, and header injection. This index lists both function tutorials so you can open mail() and ezmlm_hash() directly.
Learn mail() first. It is the function almost every PHP site uses to send email. ezmlm_hash() is only useful if you work with an EZMLM mailing list on an old PHP version.
No. It returns true when the message is accepted for delivery by the local mail system, such as sendmail or an SMTP server. The message can still bounce or land in spam. It returns false only when the hand-off itself fails.
No. ezmlm_hash() was removed in PHP 8.0. On PHP 7 and earlier it returns the EZMLM hash of an email address, which is a number from 0 to 52. If you need that value on a current PHP version, you have to implement the EZMLM hashing rule yourself.
PHP needs a mail system to send to. On Linux and macOS, set sendmail_path in php.ini. On Windows, set SMTP, smtp_port, and sendmail_from. Without these, mail() returns false or the message is dropped. Restart the web server or PHP-FPM after you change php.ini.

Start with mail()

Open the main guide—syntax, examples, and FAQs.

mail() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful