Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6910175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:50+00:00 2026-05-27T08:46:50+00:00

I am working on rebuilding a newsletter system I wrote a while ago. The

  • 0

I am working on rebuilding a newsletter system I wrote a while ago. The original system was based around using a flat file system, and I want to convert it over to MySQL. All I have left is to rebuild the end function. My problem is that I need to do is use a loop for every email stored in the database. I figured a each loop is the best way to do this, but how do you use MySQL and foreach together? Here’s my current code:

    $run = mysql_query("SELECT email FROM newsletter");    

    foreach ($run as $value) { 
        mail($value, $subject, $_POST['message'], $headers);
    }     

I’ve tried a lot of different things and nothing seems to work. I’ve even tried something like this:

        $run = mysql_query("SELECT email FROM newsletter");    
    $email = mysql_fetch_array($run, MYSQL_ASSOC)
    $cols = implode (', ', $email);
    $run2 = mysql_query("SELECT $cols FROM newsletter");    
    while($emaillist = mysql_fetch_array($run2, MYSQL_ASSOC)){ 
        foreach ($emaillist as $value) { 
            mail($value, $subject, $_POST['message'], $headers);
        }                                                                       
    } 

That was based off of a few other examples i seem. it doesnt give any errors, but it doesnt send the email. I would greatly appreciate some help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:46:51+00:00Added an answer on May 27, 2026 at 8:46 am

    You have to fetch your results. You can’t use foreach, you’ll want to use while.

    $handle = mysql_query("SELECT email FROM newsletter");    
    
    while ($row = mysql_fetch_assoc( $handle ) )
    {
        mail( $row['email'], $subject, $_POST['message'], $headers);
    }
    

    https://www.php.net/mysql_fetch_assoc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a small game using an HTML5 canvas, and javascript. And it's working
I'm working on rebuilding the UI portion of our website which is all heavily
So I'm currently working on rebuilding an existing website that is used internally at
When rebuilding a perfectly working iPhone project on iOS 4 SDK, I found out
I'm currently rebuilding an existing PHP application using Java. I therefore have an existing
I'm working on a simple CMS (based on Django, not that it matters) similar
Working on my first Web Pages project using C# and Webmatrix. So for thing
I have been working on a website using MVC Preview 1 since it came
I am working on a tile based, top-down 2D game with dinamically generated terrain,
I'm using the iCloud Key-Value Data storage solution, so I'm not working with documents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.