Page 1 of 1
emailing to a database list of emails
Posted: Wed Apr 21, 2004 11:19 am
by Skeelo
I'm haveing trouble getting this script to work. Could some one please help me, I've been stuck on this too long.
Does anyone have a better way to connect to a database and then email the people in it?
Code: Select all
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$db = "database";
$table = "table";
$rows = mysql_query("SELECT email FROM $table");
$other = "From: newsletter@domain.com";
mysql_connect ($host,$user,$pass) or die ( mysql_error ());
mysql_select_db ($db)or die ( mysql_error ());
echo "<A HREF="maillist.php">Proceed</A> <br><br>";
echo "Message Sent at ";
echo date("l g:i, F jS ");
echo "<br>";
while ( $row = mysql_fetch_row ($rows))
{
mail ( $rowїemail], $subject, $message, $other);
echo "<p>Message to $rowїemail] has been sent</p>";
}
?>
IS there something wrong with this code? I can't figure it out. [/php_man]
Posted: Wed Apr 21, 2004 11:19 am
by JayBird
Ho many emails you sending?
In what way is it not working? Error messages?
Mark
Posted: Wed Apr 21, 2004 11:22 am
by malcolmboston
theres at least 50 instances of exactly the same topic on these forums
something i answered yesterday
viewtopic.php?t=21032&highlight=mail
if you are sending large amounts of e-mails, as bech will tell you, it is recommended you open sockets and do it that way instead
Posted: Wed Apr 21, 2004 11:23 am
by Skeelo
it will be a couple hundred emails, at a time, it will be basically a newsletter. there are no errors, it will echo the proceed and the date, but as for emailing the messages it does not. i have it set up to send me a test message. i'm in the database, and its not working. I'm just getting started with php so any help/ advice you could give me would be great.
Posted: Wed Apr 21, 2004 11:25 am
by malcolmboston
a few hundred shouldnt be a problem with PHP (ive tried it and it works)
it becomes a major pani when you do 1000's and PHP max exec time fails, thus failing your site
as well as being inefficient as opposed to sockets
Posted: Wed Apr 21, 2004 11:31 am
by Skeelo
do you have anywhere where i can learn more about sockets and how to use them?
Posted: Wed Apr 21, 2004 11:37 am
by JAM
malcolmboston wrote:a few hundred shouldnt be a problem with PHP (ive tried it and it works)
it becomes a major pani when you do 1000's and PHP max exec time fails, thus failing your site
as well as being inefficient as opposed to sockets
Just to add it to the discussion; You can also tweak your settings and one/any of the following: max_execution_time (Maximum execution time of each script, in seconds), max_input_time (Maximum amount of time each script may spend parsing request data), memory_limit (Maximum amount of memory a script may consume).
http://www.faqts.com/knowledge_base/view.phtml/aid/9820 for some sockets ideas, but have the manual alongside with it.
Posted: Wed Apr 21, 2004 11:47 am
by malcolmboston
regarding maximium execution time
can you do this on a page by page basis for eg
Code: Select all
<?php
// completely pseudo
set_max_exec(180);
?>
or must you have access to the php.ini (in which case is useless as most people are hosted by companies and not on there own (editable) server)
Posted: Wed Apr 21, 2004 12:02 pm
by JAM
malcolmboston wrote:regarding maximium execution time
can you do this on a page by page basis for eg
Code: Select all
<?php
// completely pseudo
set_max_exec(180);
?>
or must you have access to the php.ini (in which case is useless as most people are hosted by companies and not on there own (editable) server)
...or by using the .htaccess file. Alot of hosting companies allows that. (As my own.)