Results 1 to 6 of 6

Thread: Sending Mail to Mailing list

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Talking 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.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Sending Mail to Mailing list

    Have you been able to retreive data from your database?

    What have you got so far?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Sending Mail to Mailing list

    This line:
    Quote 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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Re: Sending Mail to Mailing list

    Solved the problem thank you just needed a little push.
    Thanks LOTS

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width