Page 1 of 1

need some help... don't know where to start

Posted: Tue Apr 23, 2002 2:40 pm
by romeo
I have a file with 5000 lines of

email, password, name

what i want to do is read thru that file 1 line at a time and generate
5000 email messages to each address once and start off the email as

Hello $name,

blah blah

thanks, jim

Any help would be loved... I'm clueless how to start

Posted: Tue Apr 23, 2002 2:41 pm
by BigE
get the file into an array using file() then learn about while() loops and spliting the file into parts. From there you can use the mail() function to e-mail each user... I'll leave the specifics up to you but thats the general idea :D

Posted: Tue Apr 23, 2002 3:09 pm
by zoki
so easy...

Code: Select all

$f=file("your_file.txt");
$size=sizeof($f);

for ($i=0; $i<=$size; $i++)
&#123;
$line=explode(",", $f&#1111;$i]);
$email=$line&#1111;0];
$name=$line&#1111;2];
mail($email, "Hello $name", "blah blah.....");
&#125;

Posted: Tue Apr 23, 2002 4:22 pm
by jason
Just to point out... mail() was never designed to be a mass mailer. 5,000 emails might cause it to choke.

hmm

Posted: Tue Apr 23, 2002 5:43 pm
by romeo
is there a way to pause a script in the while?


because its actualluy 5 5000 line files...
the server is a beefey dual 1.2ghz... i don't know..

thanks guys

Posted: Tue Apr 23, 2002 6:56 pm
by zoki

Posted: Wed Apr 24, 2002 8:43 am
by romeo
do we think this will prevent the mail system from choking if I putt 1 second in between each or maybe 100 at a time?

Posted: Wed Apr 24, 2002 11:02 am
by jason
No, I really don't think it will.

The best way would either to use a perl shell script to run through the file, and use Sendmail directly, OR to use PHP.

The way PHP would do it would be

1. Popup a little window, and process 10 emails at a time.
2. Refresh the window every 5 seconds, and process 10 more emails.
3. Use sessions to keep track of which emails you are one.
4. It make take some time to run through all of them, but this method works for my newsletter.

well then...

Posted: Wed Apr 24, 2002 2:44 pm
by romeo
you should lemme borrow yoru script *wink wink*

this look about right?

Posted: Wed Apr 24, 2002 3:27 pm
by romeo
Parse error line 4? ocunt() doesn't work either...
Any clue?

Code: Select all

<?
$file = file("b4.txt");
$newfile = file("after.txt")
$size = sizeof($file);

for ($i; $i<$size; $i++;)
&#123;
    $line = expode(",",$file&#1111;$i]);
    $addy = $line&#1111;1];
    $msg .= $addy;
    
    $newmsg = "$msg".';'."
";

    $myfile = @fopen($newfile,"a+") or die ("fopen failed");
    @fwrite($myfile, $newmsg) or die("fwrite failed");
    fclose($myfile);
&#125;

?>

Posted: Wed Apr 24, 2002 10:46 pm
by BigE
*points to http://www.php.net/manual/en/function.file.php* while loop while loop! While loops are supposed to be used when there is an unknown value, for loops are for when you know the amount of times the loop will run! Hope that helps.

Posted: Wed Apr 24, 2002 11:04 pm
by Ruiser
Romeo,
You need a ; at the end of line 3 :
$newfile=file("after.txt");

okie...

Posted: Thu Apr 25, 2002 12:31 pm
by romeo

Code: Select all

<?
$file = file("westol.txt");
$newfile = file("westolemails.txt");
$size = sizeof($file);
$i=1;

while($i <= $size) 
&#123;
    $line = explode(",",$file&#1111;$i]);
    $addy = $line&#1111;1];
    $msg = $addy;
    
    $newmsg .= "$msg".';'."
";

    $myfile = fopen($newfile,"a+") or die ("fopen failed");
    fwrite($myfile, $newmsg) or die("fwrite failed");
    fclose($myfile);
	$i++;
&#125;

?>

Stil getting errors out the butt...

Code: Select all

Warning: Undefined variable: msg in d:htmluserspianodbcomhtml	estindex.php on line 12

Warning: Undefined variable: newmsg in d:htmluserspianodbcomhtml	estindex.php on line 14

Warning: Array to string conversion in d:htmluserspianodbcomhtml	estindex.php on line 16

Warning: fopen("Array","a+") - Permission denied in d:htmluserspianodbcomhtml	estindex.php on line 16
fopen failed

Posted: Thu Apr 25, 2002 1:56 pm
by EvilWalrus
before I get mad, I suggest reading over the filesystem functions (yes, all of them)...

Posted: Thu Apr 25, 2002 9:30 pm
by romeo
:cry:
don't get mad at me wally, i wub u man