<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.mb-send-mail" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>mb_send_mail</refname>
  <refpurpose>Send encoded mail</refpurpose>
 </refnamediv>
   
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>mb_send_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 class="union"><type>array</type><type>string</type></type><parameter>additional_headers</parameter><initializer>[]</initializer></methodparam>
   <methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>additional_params</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Sends email. Headers and messages are converted and encoded according
   to the <function>mb_language</function> setting. It's a wrapper function
   for <function>mail</function>, so see also <function>mail</function> for details.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>to</parameter></term>
     <listitem>
      <para>
       The mail addresses being sent to. Multiple
       recipients may be specified by putting a comma between each
       address in <parameter>to</parameter>. 
       This parameter is not automatically encoded.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>subject</parameter></term>
     <listitem>
      <para>
       The subject of the mail.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>message</parameter></term>
     <listitem>
      <para>
       The message of the mail.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>additional_headers</parameter> (optional)</term>
     <listitem>
      <para>
       <type>String</type> or <type>array</type> to be inserted at the end of the email header.
      </para>
      <para>
       This is typically used to add extra headers (From, Cc, and Bcc).
       Multiple extra headers should be separated with a CRLF (\r\n).
       Validate parameter not to be injected unwanted headers by attackers.
      </para>
      <para>
       If an <type>array</type> is passed, its keys are the header names and its
       values are the respective header values.
      </para>
      <note>
       <para>
        When sending mail, the mail <emphasis>must</emphasis> contain
        a <literal>From</literal> header. This can be set with the 
        <parameter>additional_headers</parameter> parameter, or a default
        can be set in &php.ini;.
       </para>
       <para>
        Failing to do this will result in an error
        message similar to <literal>Warning: mail(): "sendmail_from" not
        set in php.ini or custom "From:" header missing</literal>.
        The <literal>From</literal> header sets also
        <literal>Return-Path</literal> under Windows.
       </para>
      </note>
      <note>
       <para>
        If messages are not received, try using a LF (\n) only.
        Some Unix mail transfer agents (most notably
        <link xlink:href="&url.qmail;">qmail</link>) replace LF by CRLF
        automatically (which leads to doubling CR if CRLF is used).
        This should be a last resort, as it does not comply with
        <link xlink:href="&url.rfc;2822">RFC 2822</link>.
       </para>
      </note>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>additional_params</parameter></term>
     <listitem>
      <para>
       <parameter>additional_params</parameter> is a MTA command line
       parameter. It is useful when setting the correct Return-Path
       header when using sendmail.
      </para>
      <para>
       This parameter is escaped by <function>escapeshellcmd</function> internally
       to prevent command execution. <function>escapeshellcmd</function> prevents
       command execution, but allows to add additional parameters. For security reason,
       this parameter should be validated.
      </para>
      <para>
       Since <function>escapeshellcmd</function> is applied automatically, some characters
       that are allowed as email addresses by internet RFCs cannot be used. Programs
       that are required to use these characters <function>mail</function> cannot be used.
      </para>
      <para>
       The user that the webserver runs as should be added as a trusted user to the
       sendmail configuration to prevent a 'X-Warning' header from being added
       to the message when the envelope sender (-f) is set using this method.
       For sendmail users, this file is <filename>/etc/mail/trusted-users</filename>.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
     <row>
      <entry>8.0.0</entry>
      <entry>
       <parameter>additional_params</parameter> is nullable now.
      </entry>
     </row>
      <row>
       <entry>7.2.0</entry>
       <entry>
        The <parameter>additional_headers</parameter> parameter now also accepts
        an <type>array</type>.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>mail</function></member>
    <member><function>mb_encode_mimeheader</function></member>
    <member><function>mb_language</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- 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:"~/.phpdoc/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
-->
