PHP Mail
PHP Mail
(PHP 4, PHP 5)
mail Send mail
Description
bool mail ( string $to , string $subject , string $message [, string
$additional_headers [, string$additional_parameters ]] )
Sends an email.
Parameters
to
[email protected], [email protected]
User <[email protected]>
subject
Message to be sent.
Each line should be separated with a CRLF (\r\n). Lines should not be larger than
70 characters.
Caution
(Windows only) When PHP is talking to a SMTP server directly, if a full stop is
found on the start of a line, it is removed. To counter-act this, replace these
occurrences with a double dot.
<?php
$text = str_replace("\n.", "\n..", $text);
?>
additional_headers
(optional)
Note:
When sending mail, the mail must contain a From header. This can be set
with the additional_headers parameter, or a default can be set
in php.ini.
Failing to do this will result in an error message similar to Warning: mail():
"sendmail_from" not set in php.ini or custom "From:" header missing.
The From header sets also Return-Path under Windows.
Note:
If messages are not received, try using a LF (\n) only. Some Unix mail
transfer agents (most notably qmail) replace LF by CRLF automatically
(optional)
Return Values
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.
Changelog
Version Description
4.2.3 The additional_parameters parameter is disabled in safe_mode and the mail() function will expose a
used.
Examples
Example #1 Sending mail.
Using mail() to send a simple email:
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordw
rap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('[email protected]', 'My Subject', $message);
?>
= '[email protected]';
$to .= '[email protected]';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers
Note:
If intending to send HTML or otherwise Complex mails, it is recommended to use the
PEAR package PEAR::Mail_Mime.
Notes
Note:
The Windows implementation of mail() differs in many ways from the Unix
implementation. First, it doesn't use a local binary for composing messages but only
operates on direct sockets which means a MTA is needed listening on a network socket
(which can either on the localhost or a remote machine).
Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by
the MTA in the first place, but are parsed by PHP.