<HTML ><HEAD ><TITLE >mail</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Mail functions" HREF="ref.mail.html"><LINK REL="PREVIOUS" TITLE="ezmlm_hash" HREF="function.ezmlm-hash.html"><LINK REL="NEXT" TITLE="mailparse functions" HREF="ref.mailparse.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ezmlm-hash.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="ref.mailparse.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.mail" ></A >mail</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN43851" ></A ><P > (PHP 3, PHP 4 )</P >mail -- send mail</DIV ><DIV CLASS="refsect1" ><A NAME="AEN43854" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >mail</B > ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])<BR ></BR ><P > <B CLASS="function" >mail()</B > automatically mails the message specified in <TT CLASS="parameter" ><I >message</I ></TT > to the receiver specified in <TT CLASS="parameter" ><I >to</I ></TT >. Multiple recipients can be specified by putting a comma between each address in <TT CLASS="parameter" ><I >to</I ></TT >. 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 <A HREF="http://www.zend.com/zend/spotlight/sendmimeemailpart1.php" TARGET="_top" > Zend article</A > or the <A HREF="http://pear.php.net/Mail_Mime" TARGET="_top" > PEAR Mime Classes</A >. </P ><P > The following RFC's may also be useful: <A HREF="http://www.ietf.org/rfc/rfc1896.txt" TARGET="_top" >RFC 1896</A >, <A HREF="http://www.ietf.org/rfc/rfc2045.txt" TARGET="_top" >RFC 2045</A >, <A HREF="http://www.ietf.org/rfc/rfc2046.txt" TARGET="_top" >RFC 2046</A >, <A HREF="http://www.ietf.org/rfc/rfc2047.txt" TARGET="_top" >RFC 2047</A >, <A HREF="http://www.ietf.org/rfc/rfc2048.txt" TARGET="_top" >RFC 2048</A >, and <A HREF="http://www.ietf.org/rfc/rfc2049.txt" TARGET="_top" >RFC 2049</A >. </P ><P > <B CLASS="function" >mail()</B > returns <TT CLASS="constant" ><B >TRUE</B ></TT > if the mail was successfully accepted for delivery, <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > The Windows implementation of <B CLASS="function" >mail()</B > differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a <TT CLASS="literal" >MTA</TT > is needed listening on a network socket (which can either on the localhost or a remote machine). Second, the custom headers like <TT CLASS="literal" >From:</TT >, <TT CLASS="literal" >Cc:</TT >, <TT CLASS="literal" >Bcc:</TT > and <TT CLASS="literal" >Date:</TT > are <SPAN CLASS="strong" ><B CLASS="emphasis" >not</B ></SPAN > interpreted by the <TT CLASS="literal" >MTA</TT > in the first place, but are parsed by <TT CLASS="literal" >PHP</TT >. <TT CLASS="literal" >PHP</TT > < 4.3 only supported the <TT CLASS="literal" >Cc:</TT > header element (and was case-sensitive). <TT CLASS="literal" >PHP</TT > >= 4.3 supports all the mentioned header elements and is no longer case-sensitive. </P ></TD ></TR ></TABLE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN43907" ></A ><P ><B >Example 1. Sending mail.</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > 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. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > You must use <TT CLASS="literal" >\r\n</TT > to separate headers, although some Unix mail transfer agents may work with just a single newline (<TT CLASS="literal" >\n</TT >). </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN43916" ></A ><P ><B >Example 2. Sending mail with extra headers.</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >mail("nobody@example.com", "the subject", $message, "From: webmaster@$SERVER_NAME\r\n" ."Reply-To: webmaster@$SERVER_NAME\r\n" ."X-Mailer: PHP/" . phpversion());</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > The <TT CLASS="parameter" ><I >additional_parameters</I ></TT > parameter can be used to pass an additional parameter to the program configured to use when sending mail using the <TT CLASS="literal" >sendmail_path</TT > 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. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN43922" ></A ><P ><B >Example 3. Sending mail with extra headers and setting an additional command line parameter.</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >mail("nobody@example.com", "the subject", $message, "From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVER_NAME");</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > This fifth parameter was added in PHP 4.0.5. Since PHP 4.2.3 this parameter is disabled in <A HREF="features.safe-mode.html#ini.safe-mode" >safe_mode</A > and the <B CLASS="function" >mail()</B > function will expose a warning message and return <TT CLASS="constant" ><B >FALSE</B ></TT > if you're trying to use it. </P ></BLOCKQUOTE ></DIV ><P > You can also use simple string building techniques to build complex email messages. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN43931" ></A ><P ><B >Example 4. Sending complex email.</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >/* 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> </tr> <tr> <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);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Make sure you do not have any newline characters in the <TT CLASS="parameter" ><I >to</I ></TT > or <TT CLASS="parameter" ><I >subject</I ></TT >, or the mail may not be sent properly. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The <TT CLASS="parameter" ><I >to</I ></TT > parameter cannot be an address in the form of "Something <someone@example.com>". The mail command will not parse this properly while talking with the MTA. </P ></BLOCKQUOTE ></DIV ><P > See also <A HREF="function.imap-mail.html" ><B CLASS="function" >imap_mail()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ezmlm-hash.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="ref.mailparse.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ezmlm_hash</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.mail.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >mailparse functions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >