Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Smile [help] teach me how to send mail through email()

    hello guys,

    I have a database, and it contains users with emails and other stuff.

    I need to send them emails by the updates in my site, can I?

    I don't want to send them one by one, I want to send them all in once!

    should I use something like,

    PHP Code:

    <?php
    $users 
    "SELECT email FROM tableusers";
    $SQL_users mysql_query($users);

    $send mail($users"subject""email message");

    if (
    $send) {
        while (
    $me mysql_fetch_assoc($send)) {
            echo 
    $me['username'];
            echo 
    "-----";
            echo 
    $me['email'];
            echo 
    "---- Has been contacted";
        }
    } else {
        echo 
    "Failed";
    }

    ?>

    I just made up this code right now, to be able to delevier my question !

    Thank you in advance !
    Last edited by samoi; 12-12-2008 at 02:35 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Just move the mail() function to inside of your while loop. Searching would have yielded how to do this...
    PHP Code:
    <?php
    $users 
    "SELECT email FROM tableusers";
    $result mysql_query($users) or die(mysql_error());


        while (
    $me mysql_fetch_assoc($result)) {
    if(
    mail($me['email'], "subject""email message"))
    {
            echo 
    $me['username'];
            echo 
    "-----";
            echo 
    $me['email'];
            echo 
    "---- Has been contacted";
    }
    else
    {
    echo 
    "Failed";
    }
        }

    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by _Aerospace_Eng_ View Post
    Just move the mail() function to inside of your while loop. Searching would have yielded how to do this...
    PHP Code:
    <?php
    $users 
    "SELECT email FROM tableusers";
    $result mysql_query($users) or die(mysql_error());


        while (
    $me mysql_fetch_assoc($result)) {
    if(
    mail($me['email'], "subject""email message"))
    {
            echo 
    $me['username'];
            echo 
    "-----";
            echo 
    $me['email'];
            echo 
    "---- Has been contacted";
    }
    else
    {
    echo 
    "Failed";
    }
        }

    ?>


    Very helpful,

    Thanks a lot !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •