PHP Mail Detailed example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.