PHP mail() Function
Complete PHP Mail Reference Manual
Definition and Usage
The mail() function allows you to send email directly from a script.
Returns TRUE if the email delivery was successfully accepted, FALSE otherwise.
Syntax
mail(to,subject,message,headers,parameters)
| Parameters | Description |
|---|---|
| to | Required. Specifies the recipient of the email. |
| subject | Required. Specifies the subject of the email. **Note:** This parameter cannot contain any newline characters. |
| message | Required. Defines the message to send. Separate each line with LF (\n). Lines should not exceed 70 characters.
Windows note:When PHP connects directly to an SMTP server, a period found at the beginning of a line in the message is removed. To work around this, replace a single period with two periods: |
$txt = str_replace("n.", "n..", $txt);
?> | | headers | Optional. Specifies additional headers, such as From, Cc, and Bcc. Additional headers should be separated by CRLF (\r\n).
Note:When sending email, it must contain a From header. This can be set via this parameter or in the php.ini file.
| | parameters | Optional. Specifies additional parameters for the sendmail program (defined in the sendmail_path configuration setting). For example: when sendmail is used with the -f sendmail option, sendmail can be used to set the sender address. |Tips and Notes
**Note:** Keep in mind that acceptance of the email for delivery does not mean the email has reached its intended destination.
Example 1
Send a simple email:
Example 2
Send an email with extra headers:
Example 3
Send an HTML email:
This email contains HTML Tags!
| Firstname | Lastname |
|---|---|
| John | Doe |
Complete PHP Mail Reference Manual