email system

Discussion in 'PHP' started by radujit, Aug 12, 2012.

  1. #1
    Hi,
    I need some help with coding with mail().
    I have an sql database with 3000 records, emails of users that have signed up for my newsletter.
    Due to restrictions imposed by my host provider, I cannot send one message to more than 30 records, thus I have a major problem with managing my newsletter.
    So, what I need help with is a script that divides the 3000 records by 30, than send 100 messages delayed by 30 seconds let's say.
    Help would be highly appreciated.
    Thank you.
     
    radujit, Aug 12, 2012 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Why not send email through a 3rd party SMTP provider? Something like sendgrid.net. It sounds like you're on a shared hosting environment, and they're generally not too good when it comes to mail delivery (because other people on the server often abuse it, and the server can get blacklisted).
     
    Alex Roxon, Aug 12, 2012 IP
  3. kunalpawar15

    kunalpawar15 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can use cron job to complete this task. Make a cron that run after a time interval ( you can set it) and sends the message to the next 30 record each time.
     
    kunalpawar15, Aug 14, 2012 IP
  4. lemonsquad

    lemonsquad Greenhorn Affiliate Manager

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Assuming your doing it in a while statement I would use the sleep command.

    ie:

    while($row1 = mysql_fetch_array($r1)) {

    ////send an email to this user

    sleep('30');

    }

    Now it wouldn't work the exact way you would want but this would work. Not sure what the limit is with your provider but you may need to increase that number to make it work.

    You could also use a count var to keep track


    $counter = 0;
    while($row1 = mysql_fetch_array($r1)) {
    ++$counter;

    ////send an email to this user

    if($counter == '100') {sleep('30');unset($counter);}

    }


    I would highly recommend you use a table to track the emails sent, in the event the script stops too soon. That way you don't send the email twice to the same person.
     
    lemonsquad, Aug 21, 2012 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    Get access to a real mail server and connect and send via SMTP like someone else suggested. There are also services that will send your mail from various IP addresses etc. which increases the chances of being delivered. Local mail programs on shared servers suck.
     
    NetStar, Aug 29, 2012 IP
  6. fastestsms

    fastestsms Greenhorn

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #6
    I don't think that's your coding problem, it seems the capacity of sending mass email of your server... So find a really mass email sending server(google for it). Or you can use sleep function to send email....

    p/s: but wait.... 30s? Maybe you need to add

    at the head of your php code. Try it!
     
    fastestsms, Aug 30, 2012 IP
  7. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #7
    I second Alex's suggestion, using SMTP is the best option.

    I really got tired from email getting send to SPAM - which occurs most of the time if you use mail() function. Google SMTP is easy to use with almost all MVC's and always delivers for me.
     
    ThePHPMaster, Aug 31, 2012 IP
  8. TKY_Publishing

    TKY_Publishing Well-Known Member

    Messages:
    270
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    7
    Articles:
    28
    #8
    @fastestsms - have gotten a LOT of errors trying to use that. Working on an autoresponder script now that was troubled by that usage, and when I switched to
    ini_get('max_execution_time');
    PHP:
    the problem abruptly vanished for me.
    Have used this without fail multiple times
     
    TKY_Publishing, Jun 7, 2013 IP