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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

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

Post 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
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post 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
User avatar
zoki
Forum Newbie
Posts: 9
Joined: Tue Apr 23, 2002 3:09 pm
Location: Serbia
Contact:

Post 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;
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Just to point out... mail() was never designed to be a mass mailer. 5,000 emails might cause it to choke.
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

hmm

Post 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
User avatar
zoki
Forum Newbie
Posts: 9
Joined: Tue Apr 23, 2002 3:09 pm
Location: Serbia
Contact:

Post by zoki »

romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post 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?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

well then...

Post by romeo »

you should lemme borrow yoru script *wink wink*
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

this look about right?

Post 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;

?>
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post 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.
User avatar
Ruiser
Forum Newbie
Posts: 8
Joined: Wed Apr 24, 2002 11:04 pm
Contact:

Post by Ruiser »

Romeo,
You need a ; at the end of line 3 :
$newfile=file("after.txt");
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

okie...

Post 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
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

before I get mad, I suggest reading over the filesystem functions (yes, all of them)...
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

:cry:
don't get mad at me wally, i wub u man
Post Reply