MAIL database problem

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
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

MAIL database problem

Post by speedamp »

hello everybody....i feel like such an idiot that i can't get this right, but basically i am just wanting to loop through the table LOGIN and send each "email_login" field this templated database.

I have about 1500 records in the database and it keeps timing out.....and i have no idea how far it gets...

help!

Code: Select all

<?php

  $db = mysql_connect("localhost", ".....", "......");

  mysql_select_db(".......",$db);


$query = mysql_query("SELECT * from login");

$num = mysql_num_rows($query);
for ($i=0; $i<$num; $i++) {
$a = mysql_fetch_array($query);
$to = $a["email_login"];
$from = "management@......com";
$subject = "subject";
$mailheaders = "From: $from\n";
$mailheaders .= "Reply-To: $from\n\n";
$body = "Hello everybody,\n

MESSAGE

";
stripslashes($body);
strip_tags($body);
stripslashes($subject);
strip_tags($subject);
stripslashes($mailheaders);
strip_tags($mailheaders);
mail("$to", "$subject", "$body", "$mailheaders");
echo "sending to ".$to."";
sleep(1);
}
echo "all your emails were sent";

?>
should i use a foreach loop? how can i run this from command line so it doesn't time out?

-Michael


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Try:

Code: Select all

$from = "management@......com";
$subject = "subject";
$body = "Hello everybody,\n 

while (true)
&#123;
 $row = mysql_fetch_array($query);
 if ($row == false) break;
 $email = $row&#1111;'email'];
 mail($email, $subject, $body, "From: $from\r\n");
&#125;
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

Post by speedamp »

feyd | ***LAST WARNING*** use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php

  $db = mysql_connect("..", "..", "..");

  mysql_select_db("..._com_...",$db);


$query = mysql_query("SELECT * from login");
$from = "management@n.......com";
$subject = "Race Directors-.....";
$body = ".......,\n

NEEDTORACE.com";
stripslashes($body);
strip_tags($body);
stripslashes($subject);
strip_tags($subject);
stripslashes($mailheaders);
strip_tags($mailheaders);

while (true)
{
$row = mysql_fetch_array($query);
if ($row == false) break;
$email = $row['email_login'];
mail($email, $subject, $body, "From: $from\r\n");
echo "mailing....".$email."<br>";
}

?>
this still times out....and doesn't display ANYTHING...ugh...any suggestions?

-mike


feyd | ***LAST WARNING*** use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Mike, you gotta use

Code: Select all

tags when posting code..

your calls to strip_tags and stripslashes don't actually result in anything happening to the variables.. i.e. you need to store the return value.
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

Post by speedamp »

i'm sorry about the php problem....here is my latest and i used pagination....is this getting close?

-------------------------------------

Code: Select all

is this what you mean? something like this.... 

----------------------------------------------------------------------- 

for ($i=0; $i<200; $i++) { 
$a = mysql_fetch_array($query); 
$to = $a["email_login"]; 
$from = "management@......com"; 
$subject = "subject"; 
$mailheaders = "From: $from\n"; 
$mailheaders .= "Reply-To: $from\n\n"; 
$body = "Hello everybody,\n 

MESSAGE 

"; 
stripslashes($body); 
strip_tags($body); 
stripslashes($subject); 
strip_tags($subject); 
stripslashes($mailheaders); 
strip_tags($mailheaders); 
mail("$to", "$subject", "$body", "$mailheaders"); 
echo "sending to ".$to.""; 
sleep(1); 
} 

for ($i=200; $i<400; $i++) { 
$a = mysql_fetch_array($query); 
$to = $a["email_login"]; 
$from = "management@......com"; 
$subject = "subject"; 
$mailheaders = "From: $from\n"; 
$mailheaders .= "Reply-To: $from\n\n"; 
$body = "Hello everybody,\n 

MESSAGE 

"; 
stripslashes($body); 
strip_tags($body); 
stripslashes($subject); 
strip_tags($subject); 
stripslashes($mailheaders); 
strip_tags($mailheaders); 
mail("$to", "$subject", "$body", "$mailheaders"); 
echo "sending to ".$to.""; 
sleep(1); 
}
etc.....until $i=$num (total line numbers)
-------------------------------------------------

what about including this on line 1:

Code: Select all

<?php 
ini_set('max_execution_time', 0);
thanks!
-Michael
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I was talking about doing this:

Code: Select all

$body = strip_tags(stripslashes($body)); 
$subject = strip_tags(stripslashes($subject)); 
$mailheaders = strip_tags(stripslashes($mailheaders));
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Code: Select all

<?php

  $db = mysql_connect("..", "..", "..");

  mysql_select_db("..._com_...",$db);


$query = mysql_query("SELECT * from login");
$from = "management@n.......com";
$subject = "Race Directors-.....";
$body = ".......,\nNEEDTORACE.com";

$body = strip_tags(stripslashes($body));
$subject = strip_tags(stripslashes($subject));
$mailheaders = strip_tags(stripslashes($mailheaders));

while (true)
{
$row = mysql_fetch_array($query);
if ($row == false) break;
$email = $row['email_login'];
mail($email, $subject, $body, "From: $from\r\n");
echo "mailing....".$email."<br>";
}

?>
Post Reply