1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.37 $ -->
<reference id="ref.mail">
<title>Mail functions</title>
<titleabbrev>Mail</titleabbrev>
<partintro>
<simpara>
The <function>mail</function> function allows you to send mail
</simpara>
<variablelist>
<title>Mail Configuration Directives</title>
<varlistentry id="ini.smtp">
<term>
<parameter>SMTP</parameter>
<type>string</type>
</term>
<listitem>
<para>
DNS name or IP address of the SMTP server PHP under Windows
should use for mail sent with the <function>mail</function>
function.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sendmail-from">
<term>
<parameter>sendmail_from</parameter>
<type>string</type>
</term>
<listitem>
<para>
Which "From:" mail address should be used in mail sent from
PHP under Windows.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sendmail-path">
<term>
<parameter>sendmail_path</parameter>
<type>string</type>
</term>
<listitem>
<para>
Where the <command>sendmail</command> program can be found,
usually <filename>/usr/sbin/sendmail</filename> or
<filename>/usr/lib/sendmail</filename>
<command>configure</command> does an honest attempt of
locating this one for you and set a default, but if it fails,
you can set it here.</para>
<para>
Systems not using sendmail should set this directive to the
sendmail wrapper/replacement their mail system offers, if any.
For example, <ulink url="&url.qmail;">Qmail</ulink>
users can normally set it to
<filename>/var/qmail/bin/sendmail</filename>.</para>
</listitem>
</varlistentry>
</variablelist>
</partintro>
<refentry id="function.mail">
<refnamediv>
<refname>mail</refname>
<refpurpose>send mail</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>mail</methodname>
<methodparam><type>string</type><parameter>to</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>additional_headers</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>additional_parameters
</parameter></methodparam>
</methodsynopsis>
<simpara>
<function>mail</function> automatically mails the message
specified in <parameter>message</parameter> to the receiver
specified in <parameter>to</parameter>. Multiple recipients can
be specified by putting a comma between each address in
<parameter>to</parameter>. Email with attachments and special
types of content can be sent using this function. This is
accomplished via MIME-encoding - for more information, see this
<ulink url="&url.email.mime.zend;">
Zend article</ulink> or the <ulink url="&url.email.mime.pear;">
PEAR Mime Classes</ulink>.
</simpara>
<simpara>
The following RFC's may also be useful:
<ulink url="&url.rfc1896;">RFC 1896</ulink>,
<ulink url="&url.rfc2045;">RFC 2045</ulink>,
<ulink url="&url.rfc2046;">RFC 2046</ulink>,
<ulink url="&url.rfc2047;">RFC 2047</ulink>,
<ulink url="&url.rfc2048;">RFC 2048</ulink>, and
<ulink url="&url.rfc2049;">RFC 2049</ulink>.
</simpara>
<para>
<function>mail</function> returns &true; if the mail
is successfully sent, &false; otherwise.
</para>
<para>
<example>
<title>Sending mail.</title>
<programlisting>
<![CDATA[
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");
]]>
</programlisting>
</example></para>
<simpara>
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.
</simpara>
<note>
<para>
You must use <literal>\r\n</literal> to seperate headers, although
some Unix mail transfer agents may work with just a single newline
(<literal>\n</literal>). The Cc: header is case sensitive and must
be written as <literal>Cc:</literal> on Win32 systems. The Bcc:
header is also not supported on Win32 systems.
</para>
</note>
<para>
<example>
<title>Sending mail with extra headers.</title>
<programlisting>
<![CDATA[
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\r\n"
."Reply-To: webmaster@$SERVER_NAME\r\n"
."X-Mailer: PHP/" . phpversion());
]]>
</programlisting>
</example>
</para>
<para>
The <parameter>additional_parameters</parameter> parameter
can be used to pass additional parameters to the program configured
to use when sending mail using the <literal>sendmail_path</literal>
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.
<example>
<title>Sending mail with extra headers and setting an additional command line parameter.</title>
<programlisting>
<![CDATA[
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVER_NAME");
]]>
</programlisting>
</example>
</para>
<note>
<para>
This fifth parameter was added in PHP 4.0.5.
</para>
</note>
<para>
You can also use simple string building techniques to build complex
email messages.
<example>
<title>Sending complex email.</title>
<programlisting>
<![CDATA[
/* 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);
]]>
</programlisting>
</example>
</para>
<note>
<para>
Make sure you do not have any newline characters in the
<parameter>to</parameter> or <parameter>subject</parameter>,
or the mail may not be sent properly.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ezmlm-hash">
<refnamediv>
<refname>ezmlm_hash</refname>
<refpurpose>Calculate the hash value needed by EZMLM</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>ezmlm_hash</methodname>
<methodparam><type>string</type><parameter>addr</parameter></methodparam>
</methodsynopsis>
<simpara>
<function>ezmlm_hash</function> calculates the hash value needed
when keeping EZMLM mailing lists in a MySQL database.
</simpara>
<para>
<example>
<title>Calculating the hash and subscribing a user</title>
<programlisting>
<![CDATA[
$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
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|