Page 1 of 1
MAIL database problem
Posted: Thu Jul 15, 2004 5:53 pm
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]
Posted: Thu Jul 15, 2004 5:57 pm
by Joe
Try:
Code: Select all
$from = "management@......com";
$subject = "subject";
$body = "Hello everybody,\n
while (true)
{
$row = mysql_fetch_array($query);
if ($row == false) break;
$email = $rowї'email'];
mail($email, $subject, $body, "From: $from\r\n");
}
Posted: Thu Jul 15, 2004 8:59 pm
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]
Posted: Thu Jul 15, 2004 9:11 pm
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.
Posted: Fri Jul 16, 2004 3:01 pm
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
Posted: Fri Jul 16, 2004 3:43 pm
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));
Posted: Fri Jul 16, 2004 4:46 pm
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>";
}
?>