16c04-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 61 行

PHP
61
字号
<?php// Require the mass mailing library://require_once 'mass_email.php';require_once '16c03-2.php';// Create an array of email addresses of our subscribers.$subscribers = array('example@eliw.com', 'php@example.com',     'crossbow@example.com', 'eliwhite@example.com',     'SiegfriedFaust@example.com', 'hyper@example.com');// Now, first of all, the entire email (header/body) should be waiting// for us as stdin.  So read it all into memory so we can process it.$msg = file_get_contents('php://stdin');// Now, we need to separate the header from the body, look for the first// double line break to detect this - look for the Unix method: \n\n// and the Windows style of \r\n for each break.list($head, $body) = preg_split("/\n\n|[\r\n][\r\n][\r\n][\r\n]/", $msg, 2);// Now there are various parts of the header that we need to know.// It will be easier to parse each of these out of the header if we have// separate lines, so split it as such:$headlines = explode("\n", $head);// Now, set some default values in case we can't determine some of these:$from = 'familylist@example.com';$subject = '[No Subject]';// Now, loop through each header line - Save our data, and KILL the line.foreach ($headlines as $key => $line) {    // If this is 'from'    if (strncasecmp($line, 'From:', 5) === 0) {        // snag the From and store it:        $from = trim(substr($line, 5));                // Now destroy this one:        unset($headlines[$key]);    }    // Else if this is the Subject    elseif (strncasecmp($line, 'Subject:', 8) === 0) {        // Grab the subject line        $subject = trim(substr($line, 8));        // Now destroy the original.        unset($headlines[$key]);    }}// We are read to rebroadcast this email to everyone with a few changes.// We are going to leave the 'From', the same, but set a Sender: of the list// address so that it is obvious that this was sent to/from the list.// Also add a prefix to the subject so people know that it came from a list:// Attempt to keep all other headers intact!// Add in the Sender header to the line listing:$headlines[] = 'Sender: familylist@example.com';// Send that mass email to everyone!mass_email($subscribers, $from, '[Family] ' . $subject,     $body, 'mail.example.com',    implode("\n", $headlines) );?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?