From:http://php.net/manual/zh/function.mail.php
Example #1 sending mail.
Using Mail () to send a simple email:
<?php
The message
$message="Line 1\nline 2\nline 3";
In case all of our lines is larger than characters, we should use WordWrap ()
$message = wordwrap($message, +);
Send
Mail(' [email protected] ', ' My Subject ', $message);
?>
Example #2 sending mail with extra headers.
The addition of basic headers, telling the MUA the From and reply-to addresses:
<?php
$to=' [Email protected] ';
$subject=' The subject ';
$message=' Hello ';
$headers=' From: [email protected] '."\ r \ n" ' reply-to: [email protected] ' . \ r \ n " ' x-mailer: php/' . phpversion ();
mail $to , $subject , $message , $ Headers);
?>
Example #3 sending mail with a additional command line parameter.
The additional_parameters
parameter can used to pass a additional parameter to the program configured to use when sending mail using t He Sendmail_path.
<?php
mail(‘[email protected]‘, ‘the subject‘, ‘the message‘, null,
‘[email protected]‘);
?>
Example #4 Sending HTML email
It is also possible to send HTML email with Mail ().
<?php
Multiple recipients
$to=' [Email protected] '.‘, ‘;Note the comma
$to.=' [Email protected] ';
Subject
$subject=' Birthday Reminders for August ';
Message
$message=‘
<title>birthday Reminders for August</title>
<body>
<p>here is 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>
‘;
To send HTML mail, the Content-type header must is set
$headers=' mime-version:1.0 '."\ r \ n";
$headers.=' Content-type:text/html; Charset=iso-8859-1 '."\ r \ n";
Additional headers
$headers.=' To:mary <[email protected]>, Kelly <[email protected]> '."\ r \ n";
$headers.=' From:birthday Reminder <[email protected]> '."\ r \ n";
$headers.=' Cc: [email protected] '. "\ r \ n";
$headers . = ' BCC: [email protected] ' . "\ r \ n";
Mail it
Mail($to, $subject, $message, $headers);
?>
PHP Mail Detailed example