Mail functions
Mail
The mail function allows you to send mail
Mail Configuration Directives
SMTP
string
DNS name or IP address of the SMTP server PHP under Windows
should use for mail sent with the mail
function.
sendmail_from
string
Which "From:" mail address should be used in mail sent from
PHP under Windows.
sendmail_path
string
Where the sendmail program can be found,
usually /usr/sbin/sendmail or
/usr/lib/sendmail
configure does an honest attempt of
locating this one for you and set a default, but if it fails,
you can set it here.
Systems not using sendmail should set this directive to the
sendmail wrapper/replacement their mail system offers, if any.
For example, Qmail
users can normally set it to
/var/qmail/bin/sendmail.
mail
send mail
Description
bool mail
string to
string subject
string message
string
additional_headers
string
additional_parameters
mail automatically mails the message
specified in message to the receiver
specified in to. Multiple recipients can
be specified by putting a comma between each address in
to. Email with attachments and special
types of content can be sent using this function. This is
accomplished via MIME-encoding - for more information, see
http://www.zend.com/zend/spotlight/sendmimeemailpart1.php or
RFC 1896).
mail returns &true; if the mail
is successfully sent, &false; otherwise.
Sending mail.
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");
If a fourth string argument is passed, this string is inserted at
the end of the header. This is typically used to add extra
headers. Multiple extra headers are separated with a carriage return
and newline.
You must use \r\n to seperate headers, although
some Unix mail transfer agents may work with just a single newline
(\n). The Cc: header is case sensitive and must
be written as Cc: on Win32 systems. The Bcc:
header is also not supported on Win32 systems.
Sending mail with extra headers.
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\r\n"
."Reply-To: webmaster@$SERVER_NAME\r\n"
."X-Mailer: PHP/" . phpversion());
The additional_parameters parameter
can be used to pass additional parameters to the program configured
to use when sending mail using the sendmail_path
configuration setting. For example, this can be used to set the
envelope sender address when using sendmail. You may need to add
the user that your web server runs as to your sendmail configuration
to prevent a 'X-Warning' header from being added to the message when
you set the envelope sender using this method.
Sending mail with extra headers and setting an additional command line parameter.
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVER_NAME");
This fifth parameter was added in PHP 4.0.5.
You can also use simple string building techniques to build complex
email messages.
Sending complex email.
/* recipients */
$to = "Mary <mary@example.com>" . ", " ; //note the comma
$to .= "Kelly <kelly@example.com>";
/* 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>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";
/* and now mail it */
mail($to, $subject, $message, $headers);
Make sure you do not have any newline characters in the
to or subject,
or the mail may not be sent properly.
ezmlm_hash
Calculate the hash value needed by EZMLM
Description
int ezmlm_hash
string addr
ezmlm_hash calculates the hash value needed
when keeping EZMLM mailing lists in a MySQL database.
Calculating the hash and subscribing a user
$user = "joecool@example.com";
$hash = ezmlm_hash ($user);
$query = sprintf ("INSERT INTO sample VALUES (%s, '%s')", $hash, $user);
$db->query($query); // using PHPLIB db interface