|
-
May 7th, 2007, 06:55 AM
#1
Thread Starter
Junior Member
Sending Mail to Mailing list
Hello everyone,
I m a little stuck with a problem here. How do I email a message to all the email addresses in my Mysql database? I believe I need to use arrays but I am not very familiar with them. Please help.
-
May 7th, 2007, 06:56 AM
#2
Re: Sending Mail to Mailing list
Have you been able to retreive data from your database?
What have you got so far?
-
May 8th, 2007, 04:33 AM
#3
Thread Starter
Junior Member
Re: Sending Mail to Mailing list
Yes I have managed to get info from the database and echo it. I've also managed to update it and delete it. I know how to send mail to an address inthe code but I don't know much about arrays amd iteration ..I know I should use one of or a combination of the two...but how.
CODE:
Code:
<?php
//SQLUtils contains all the details of the database connection
require_once('SQL_Utils1.php');
//connect to the database
$dbConn = getDatabaseConnection();
if($query = "SELECT * FROM Mail_List") {
//if query does run print message
echo "done ";
//otherwise if query does not run print message
}else{
echo 'Problem';
echo '<br>';
}
//this is a bit of borowed code which didn t work
while($row = mysql_fetch_array($query)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
}
$result = runQuery($query, $dbConn);
//end connection to db
disconnectFromDatabase($dbConn);
?>
Last edited by stephanief; May 8th, 2007 at 04:53 AM.
-
May 8th, 2007, 06:10 AM
#4
Re: Sending Mail to Mailing list
This line:
 Originally Posted by stephanief
Code:
if($query = "SELECT * FROM Mail_List")
does not execute anything. What that statement does is assign the query text to the $query variable, and then test whether it can be evaluated to true or not, which it can because anything that isn't false or null is true. So it will always return true.
What you need to do, presumably, is this:
PHP Code:
$dbConn = getDatabaseConnection();
$query = "SELECT * FROM Mail_List";
if ($result = runQuery($query, $dbConn)) {
// it worked
}
else {
// it didn't
}
Assuming1 that $result is a MySQL resultset resource, you can then do this (in the "it worked" part):
PHP Code:
while ($row = mysql_fetch_assoc($result)) {
// magic here
}
In each iteration, $row will point to an array containing the field values. Use mail() to send an email.
1. I can't help any more than that at this point, as I am not aware of your database schema or how the SQL_Utils1.php script works.
-
May 11th, 2007, 07:45 AM
#5
Thread Starter
Junior Member
Re: Sending Mail to Mailing list
Solved the problem thank you just needed a little push.
Thanks LOTS
-
May 11th, 2007, 07:52 AM
#6
Re: Sending Mail to Mailing list
You're very welcome and now that the problem is solved we would appreciate it if you could help us out by marking it as such using the Thread Tools menu above the first post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|