|
|
|
Description
Description
</H2
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN22529"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>bool <B
CLASS="function"
>mail</B
></CODE
> (string to, string subject, string message [, string
additional_headers [, string
additional_parameters]])</CODE
></P
><P
></P
></DIV
><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
>.
</P
><P
> <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN22551"
></A
><P
><B
>Example 1. Sending mail.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> mail("rasmus@lerdorf.on.ca", "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 newline.
</P
><P
> If the fifth parameter is supplied, PHP will add this data
to the call to the mailer. This is useful when setting the
correct Return-Path header when using sendmail.
</P
><P
> <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN22557"
></A
><P
><B
>Example 2. Sending mail with extra headers.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> mail("nobody@aol.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME\nX-Mailer: PHP/" .version());
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
With the fifth parameter you can set additional command line parameters to
the actual mailer. In the example below we set the correct Return-Path
header for sendmail. Normally sendmail will add the X-Authentication-Warning
header when using the -f parameter, because the webserver user is probably
not a member of the trusted users. To suppress this warning, you should add
the web server user to the trusted users in your sendmail config file.
<TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN22560"
></A
><P
><B
>Example 3. Sending mail with extra headers and setting an additional command line parameter.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> mail("nobody@aol.com", "the subject", $message,
"From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVERNAME");
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
You can also use fairly 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="AEN22563"
></A
><P
><B
>Example 4. Sending complex email.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> /* recipients */
$recipient .= "Mary <mary@u.college.edu>" . ", " ; //note the comma
$recipient .= "Kelly <kelly@u.college.edu>" . ", ";
$recipient .= "ronabop.net";
/* subject */
$subject = "Birthday Reminders for August";
/* message */
$message .= "The following email includes a formatted ASCII table\n";
$message .= "Day \t\tMonth \t\tYear\n";
$message .= "3rd \t\tAug \t\t1970\n";
$message .= "17rd\t\tAug \t\t1973\n";
/* you can add a stock signature */
$message .= "--\r\n"; //Signature delimiter
$message .= "Birthday reminder copylefted by public domain";
/* additional header pieces for errors, From cc's, bcc's, etc */
$headers .= "From: Birthday Reminder <birthday.net>\n";
$headers .= "X-Sender: <birthday.net>\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: <birthday.net>\n"; // Return path for errors
/* If you want to send html mail, uncomment the following line */
// $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
$headers .= "cc:birthdayarchive.net\n"; // CC to
$headers .= "bcc:birthdaycheck.net, birthdaygifts.net\n"; // BCCs to
/* and now mail it */
mail($recipient, $subject, $message, $headers);
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
</P
></DIV
>
|
|
| Email Class Categories : PHP, Mail, PHP Classes | | | Protect your email links from being spidered by spam email robots! Categories : PHP, Security, Mail, Email | | | Data Retrieve from mailbox and generate the SQL Syntax Categories : PHP, IMAP, Mail | | | XPertMailer - Sends TRUE Mails Categories : PHP, Mail, SMTP, PHP Classes | | | Tell a friend script :) Categories : PHP, Mail | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Simple Maiing list with newsletter support Categories : PHP, PHP Classes, Mail | | | tinySendMail and tinySockMail functions for generating SMTP mail within PHP Categories : PHP, Mail, SMTP | | | Convert text to 'quoted printable' without the IMAP package installed. Categories : PHP, Mail, IMAP | | | Sending mail to a mailing list and showing progress Categories : PHP, Mail, Beginner Guides | | | ezmlm_hash -- Calculate the hash value needed by EZMLM Categories : PHP, PHP Functions, Mail | | | send php mail with form data and attachment. Categories : PHP, Email, Mail, Form Processing | | | Using this script anyone can easily get a form result to his/her mailbox. You can use this script for any form 2 mail purpose. Categories : PHP, Mail, Form Processing | | | Password reminder Categories : PHP, PHP Classes, Databases, MySQL, Mail | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | |
|
|
|