Backend Development 3 min read

PHP mail() Function – Sending Email

This article explains PHP's mail() function, detailing its parameters, usage cautions, return values, and provides a complete code example for sending an email via SMTP, including formatting of recipient addresses, subject line restrictions, message body limits, and header construction.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP mail() Function – Sending Email

PHP's mail() function sends an email.

Parameters

to – Recipient email address or list. Must follow RFC 2822 format, e.g., [email protected] , [email protected], [email protected] , User <[email protected]> , or User <[email protected]>, Another User <[email protected]> .

subject – Email subject. This field must not contain any line‑break characters.

message – Message body. Lines must be separated by a LF (\n) and each line may not exceed 70 characters.

Caution – On Windows, if a line begins with a single period, it may be stripped; replace a single period with two periods to avoid this issue.

Return value – Returns TRUE if the mail was successfully accepted for delivery, otherwise FALSE .

Example

BackendphpfunctionemailSMTPMail
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.