Re: Inserting function into mail()???

From: Date: Wed, 17 Dec 2003 15:09:07 +0000
Subject: Re: Inserting function into mail()???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172883@lists.php.net to get a copy of this message
"Tristan Pretty" <Tristan.Pretty@risk.sungard.com> wrote in message news:OF7E3FABFC.9B1FB796-ON80256DFF.004AD4D0-80256DFF.004B52D0@risk.sungard.com... > 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("me@mysite.com", "$abc", "$abc", "From: > them@mysite.com"); > $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("me@mysite.com", "$abc", "$abc", "From: them@mysite.com"); $i++; } ?> <HTML> <BODY> Mails sent! </BODY> </HTML>

« previous php.general (#172883) next »