• 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);
    ?>
  • 相关阅读:
    ubuntu部分端口命令的使用----开启端口/开启防火墙
    ElasticSearch 5.0及head插件安装
    维基百科语料中的词语相似度探索
    Mac下多版本JDK安装
    Mac OS 终端利器 iTerm2
    android mat 转 bitmap
    simHash 简介以及 java 实现
    Python数据可视化之matplotlib实践 源码 第二篇 精进 第六章
    Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章
    Python数据可视化之matplotlib实践 源码 第一篇 入门 第四章
  • 原文地址:https://www.cnblogs.com/boonya/p/5063398.html
Copyright © 2020-2023  润新知