<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Send encoded mail</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mb-scrub.html">mb_scrub</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mb-split.html">mb_split</a></div> <div class="up"><a href="ref.mbstring.html">Multibyte String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.mb-send-mail" class="refentry"> <div class="refnamediv"> <h1 class="refname">mb_send_mail</h1> <p class="verinfo">(PHP 4 >= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mb_send_mail</span> — <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="type">bool</span> <span class="methodname"><strong>mb_send_mail</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$to</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$subject</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$additional_headers</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$additional_parameter</code><span class="initializer"> = <strong><code>NULL</code></strong></span></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.html" class="function">mb_language()</a></span> setting. It's a wrapper function for <span class="function"><a href="function.mail.html" class="function">mail()</a></span>, so see also <span class="function"><a href="function.mail.html" 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.html" class="type String">String</a></span> or <span class="type"><a href="language.types.array.html" 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.html" 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 class="emphasis">must</em> contain a <em>From</em> 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 <em>Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing</em>. The <em>From</em> header sets also <em>Return-Path</em> 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://www.qmail.org/" class="link external">» 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="http://www.faqs.org/rfcs/rfc2822" class="link external">» RFC 2822</a>. </p> </p></blockquote> </dd> <dt> <code class="parameter">additional_parameter</code></dt> <dd> <p class="para"> <code class="parameter">additional_parameter</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.html" class="function">escapeshellcmd()</a></span> internally to prevent command execution. <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> prevents command execution, but allows to add addtional parameters. For security reason, this parameter should be validated. </p> <p class="para"> Since <span class="function"><a href="function.escapeshellcmd.html" 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.html" 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 '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 <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>TRUE</code></strong> on success or <strong><code>FALSE</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>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.html" 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 class="member"><span class="function"><a href="function.mail.html" class="function" rel="rdfs-seeAlso">mail()</a> - Send mail</span></li> <li class="member"><span class="function"><a href="function.mb-encode-mimeheader.html" class="function" rel="rdfs-seeAlso">mb_encode_mimeheader()</a> - Encode string for MIME header</span></li> <li class="member"><span class="function"><a href="function.mb-language.html" class="function" rel="rdfs-seeAlso">mb_language()</a> - Set/Get current language</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mb-scrub.html">mb_scrub</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mb-split.html">mb_split</a></div> <div class="up"><a href="ref.mbstring.html">Multibyte String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>