<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mbstring.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.mb-send-mail.php',
    1 => 'mb_send_mail',
    2 => 'Send encoded mail',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => 'Multibyte String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.mb-scrub.php',
    1 => 'mb_scrub',
  ),
  'next' => 
  array (
    0 => 'function.mb-split.php',
    1 => 'mb_split',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mbstring/functions/mb-send-mail.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mb-send-mail" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_send_mail</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_send_mail</span> &mdash; <span class="dc-title">Send encoded mail</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-send-mail-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_send_mail</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$to</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$subject</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$message</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$additional_headers</code><span class="initializer"> = []</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$additional_params</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Sends email. Headers and messages are converted and encoded according
   to the <span class="function"><a href="function.mb-language.php" class="function">mb_language()</a></span> setting. It&#039;s a wrapper function
   for <span class="function"><a href="function.mail.php" class="function">mail()</a></span>, so see also <span class="function"><a href="function.mail.php" class="function">mail()</a></span> for details.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-send-mail-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">to</code></dt>
     <dd>
      <p class="para">
       The mail addresses being sent to. Multiple
       recipients may be specified by putting a comma between each
       address in <code class="parameter">to</code>. 
       This parameter is not automatically encoded.
      </p>
     </dd>
    
    
     <dt><code class="parameter">subject</code></dt>
     <dd>
      <p class="para">
       The subject of the mail.
      </p>
     </dd>
    
    
     <dt><code class="parameter">message</code></dt>
     <dd>
      <p class="para">
       The message of the mail.
      </p>
     </dd>
    
    
     <dt><code class="parameter">additional_headers</code> (optional)</dt>
     <dd>
      <p class="para">
       <span class="type"><a href="language.types.string.php" class="type String">String</a></span> or <span class="type"><a href="language.types.array.php" class="type array">array</a></span> to be inserted at the end of the email header.
      </p>
      <p class="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.
      </p>
      <p class="para">
       If an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> is passed, its keys are the header names and its
       values are the respective header values.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        When sending mail, the mail <em>must</em> contain
        a <code class="literal">From</code> header. This can be set with the 
        <code class="parameter">additional_headers</code> parameter, or a default
        can be set in <var class="filename">php.ini</var>.
       </p>
       <p class="para">
        Failing to do this will result in an error
        message similar to <code class="literal">Warning: mail(): &quot;sendmail_from&quot; not
        set in php.ini or custom &quot;From:&quot; header missing</code>.
        The <code class="literal">From</code> header sets also
        <code class="literal">Return-Path</code> under Windows.
       </p>
      </p></blockquote>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        If messages are not received, try using a LF (\n) only.
        Some Unix mail transfer agents (most notably
        <a href="http://cr.yp.to/qmail.html" class="link external">&raquo;&nbsp;qmail</a>) 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
        <a href="https://datatracker.ietf.org/doc/html/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a>.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">additional_params</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">additional_params</code> is a MTA command line
       parameter. It is useful when setting the correct Return-Path
       header when using sendmail.
      </p>
      <p class="para">
       This parameter is escaped by <span class="function"><a href="function.escapeshellcmd.php" class="function">escapeshellcmd()</a></span> internally
       to prevent command execution. <span class="function"><a href="function.escapeshellcmd.php" class="function">escapeshellcmd()</a></span> prevents
       command execution, but allows to add additional parameters. For security reason,
       this parameter should be validated.
      </p>
      <p class="para">
       Since <span class="function"><a href="function.escapeshellcmd.php" class="function">escapeshellcmd()</a></span> 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 <span class="function"><a href="function.mail.php" class="function">mail()</a></span> cannot be used.
      </p>
      <p class="para">
       The user that the webserver runs as should be added as a trusted user to the
       sendmail configuration to prevent a &#039;X-Warning&#039; header from being added
       to the message when the envelope sender (-f) is set using this method.
       For sendmail users, this file is <var class="filename">/etc/mail/trusted-users</var>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-send-mail-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mb-send-mail-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">additional_params</code> is nullable now.
      </td>
     </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        The <code class="parameter">additional_headers</code> parameter now also accepts
        an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-send-mail-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mail.php" class="function" rel="rdfs-seeAlso">mail()</a> - Send mail</span></li>
    <li><span class="function"><a href="function.mb-encode-mimeheader.php" class="function" rel="rdfs-seeAlso">mb_encode_mimeheader()</a> - Encode string for MIME header</span></li>
    <li><span class="function"><a href="function.mb-language.php" class="function" rel="rdfs-seeAlso">mb_language()</a> - Set/Get current language</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>