"Tristan Pretty" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ok, here's my code that I want to pick a random line from a text file, and
> then mail myself 10 times with a different line each time...
> But It simply won't work...
> Anyone know why?
>
> <?
>     function randomline($filename) {
>     $file = file($filename);
>     srand((double)microtime()*1000000);
>     $abc = $file[rand(0,count($file))];
>     }
> $i = 0;
> while (2 > $i) {
> $abc = randomline('text.txt');
> mail("[EMAIL PROTECTED]", "$abc", "$abc", "From: [EMAIL PROTECTED]");
> $i++;
> }
> ?>
>
> <HTML>
> <BODY>
> Mails sent!
> </BODY>
> </HTML>
>
>

The problem in your code is that your function does'nt have a return
statement.

That means that $abc will contain nothing after
$abc = randomline('text.txt');

Here is the code that will work:

<?
    function randomline($filename) {
    $file = file($filename);
    srand((double)microtime()*1000000);
    return $file[rand(0,count($file))];
    }
$i = 0;
while (2 > $i) {
$abc = randomline('text.txt');
mail("[EMAIL PROTECTED]", "$abc", "$abc", "From: [EMAIL PROTECTED]");
$i++;
}
?>

<HTML>
<BODY>
Mails sent!
</BODY>
</HTML>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to