PHP mail详细示例

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 Line 2 Line 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message wordwrap($message70);

// Send
mail('caffinated@example.com''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      'nobody@example.com';
$subject 'the subject';
$message 'hello';
$headers 'From: webmaster@example.com' " " .
    'Reply-To: webmaster@example.com' " " .
    'X-Mailer: PHP/' phpversion();

mail($to$subject$message$headers);
?>

Example #3 Sending mail with an additional command line parameter.

The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path.

<?php
mail('nobody@example.com''the subject''the message'null,
   '-fwebmaster@example.com');
?>

Example #4 Sending HTML email

It is also possible to send HTML email with mail().

<?php
// multiple recipients
$to  'aidan@example.com' ', '// note the comma
$to .= 'wez@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, the Content-type header must be set
$headers  'MIME-Version: 1.0' " ";
$headers .= 'Content-type: text/html; charset=iso-8859-1' " ";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' " ";
$headers .= 'From: Birthday Reminder <birthday@example.com>' " ";
$headers .= 'Cc: birthdayarchive@example.com' " ";
$headers .= 'Bcc: birthdaycheck@example.com' " ";

// Mail it
mail($to$subject$message$headers);
?>
原文地址:https://www.cnblogs.com/boonya/p/5063398.html