Making a php mail function send to everyone in database but 1 person every minute

Discussion in 'PHP' started by shivampaw, Nov 2, 2013.

  1. #1
    I have a database of users with their emails but as my hosting provider doesn't allow mass emails I was wondering if there is a way so that I can send the same email to everyone in the database but 1 person ever 1 minute. So that It sends to person '1' and waits one minute then sends to person '2' and waits one minutes and keeps doing that till it has sent to everyone. I have php and html knowledge and also a bit of javascript.

    Thanks
     
    Solved! View solution.
    shivampaw, Nov 2, 2013 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    How many users do you have in your database?
     
    nico_swd, Nov 2, 2013 IP
  3. shivampaw

    shivampaw Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    I have about 30 and it is increasing every day.
     
    shivampaw, Nov 2, 2013 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Okay, well you could run a script in the background, perhaps as cron job, and sleep() one minute after every email. As long as you don't have many users, it won't be a problem. But once there's more, you should look for an alternative method.

    
    set_time_limit(0);
    ignore_user_abort(true);
    
    while (/* ... */)
    {
        mail(/* ... */)
        sleep(60);
    }
    
    PHP:
    ... alternatively, you could sign up for Amazon SES, and send your emails through their servers. This way you don't have these limitations. It's very cheap too.
     
    nico_swd, Nov 2, 2013 IP
  5. shivampaw

    shivampaw Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    What do i use to send the email to all users and how do i pull them all into a variable.

    What about google apps and sending through their servers? If i use google apps how can I send it to all users easily?
     
    shivampaw, Nov 2, 2013 IP
  6. #6
    If you have all your e-mails in a database you can use the following code:
    
    <?PHP
    $conn = mysql_connect('localhost', 'db_username', 'db_password');
    mysql_select_db('db_name', $conn);
    
    $sql = "SELECT * FROM table";
    $result = mysql_query($sql);
    
    while($row = mysql_fetch_array($result))
    {
    mail($row[email_column_name],"Subject","E-Mail Body");
    sleep(60);
    }
    ?>
    
    Code (markup):
     
    Pudge1, Nov 2, 2013 IP
  7. shivampaw

    shivampaw Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    Hi Guys,

    What I did is echoed out all the usernames and emails from my table to a file then used MaxBulk Mailer and connected to my google apps account. Then I loaded the emails from web page and boom they all popped up which then allowed me to create a nice message and send to all users.

    This is what the email looked like.

    [​IMG]
     
    shivampaw, Nov 2, 2013 IP
  8. rehan.khalid.9235

    rehan.khalid.9235 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    85
    #8
    Well, i am using 'phpmailer' class to send emails to my users. This class handles all things, even customized template of Email.

    have look at this tutorial:-

    http://www.rashflash.com/index.php/projectcontroller/displayProjectExplanation/send-email-using-php
     
    rehan.khalid.9235, Nov 4, 2013 IP