开发者

How do I return data to my mailer in PHP?

I know the title is vague, but I will attempt to explain. I new to PHP and am writing a simple parser that handles log files from a program and I am stuck right now with getting it to give me a list of the file names. I have cut out some of the irrelevant code and ensured it works.

<?php 


$inputFile = fopen("sampleScan2.html", "r");
$fileLocation = '';

function getFileList($inputFile)
{
    $line = '';
    $owner = '';
    global $fileLocations;
    $fileLocation = '';

    while (!feof($inputFile)) 
    {
        if (substr($line, 0, 1) != '    ')
        {
            $dom = new DOMDocument();
            $dom->preserveWhiteSpace = FALSE;
            @$dom->loadHTML($line);
            $tdElement = $dom->getElementsByTagName('td');
            $elementCount = $tdElement->length;
            for ($i=0; $i<$elementCount; $i++)
  开发者_开发百科          {
                if ($i == 1)
                {
                    $fileLocation = $tdElement->item($i)->nodeValue;

                }
                if ($i== 6)
                {
                    $owner = $tdElement->item($i)->nodeValue;           
                }
            }
            echo $fileLocation . '<br>'; //Gives me correct file locations
        }
        $line = fgets($inputFile);
    }
}
//Send actual mail message
    $headers =  'MIME-Version: 1.0' . "\r\n" . PHP_EOL .
                'Content-type: text/html; charset=iso-8859-1' . "\r\n" . PHP_EOL .
                'From: "Jane Smith" <jsmith@endof.it>' . "\r\n" . PHP_EOL .
                'X-Mailer: PHP-' . phpversion() . PHP_EOL;
    $to =       '"John Smith" <jsmith@theInter.net>';
    $subject =  'Report';
    $message =  '\'' . getFileList($inputFile) . '\'' . '<br>'; //Call to get the file locations
    mail($to, $subject, $message, $headers);
fclose($inputFile);
?> 

So basically I want to be able to call some function in the mailing portion of the code and have a list returned to that point. Any help is greatly appreciated.


A list of what? The files being generated in getFileList? The getFileList isn't generating a list, it's simply outputting the files as they're found, which means there's nothing to return back up to your $mesage = ... function.

At minimum you'd need something like:

function getFileList(...) {
    $filelist = array();
    for (...) {
       $filelist[] = ...;
    }
    return $filelist;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜