• 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);
    ?>
  • 相关阅读:
    scrapy xpath 定位节点获取数据
    pandas 获取增量数据
    10秒解决80端口被占用
    VS code 自定义快捷键
    解决npm 的 shasum check failed for错误
    JSON.parse与eval的区别
    display:flex,用这个布局就像开挂了!!!
    几款前端IDE工具:Sublime、Atom、VSCode比较
    npm install -S -D -g 有什么区别
    Vue框架学习——使用nvm下载8.12.0以后版本没有npm文件的解决办法
  • 原文地址:https://www.cnblogs.com/boonya/p/5063398.html
Copyright © 2020-2023  润新知