emailing to a database list of emails

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
Skeelo
Forum Newbie
Posts: 3
Joined: Wed Apr 21, 2004 11:19 am
Location: Nashville

emailing to a database list of emails

Post 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))
&#123;
mail ( $row&#1111;email], $subject, $message, $other);
echo "<p>Message to $row&#1111;email] has been sent</p>";
&#125;
?>
IS there something wrong with this code? I can't figure it out. [/php_man]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Ho many emails you sending?

In what way is it not working? Error messages?

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
Skeelo
Forum Newbie
Posts: 3
Joined: Wed Apr 21, 2004 11:19 am
Location: Nashville

Post 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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
Skeelo
Forum Newbie
Posts: 3
Joined: Wed Apr 21, 2004 11:19 am
Location: Nashville

Post by Skeelo »

do you have anywhere where i can learn more about sockets and how to use them?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.)
Post Reply