PHP Newsletter

Discussion in 'PHP' started by PET, Mar 21, 2007.

  1. #1
    Hello,

    I really hope I will get some answers.

    I have to do a PHP newsletter that will take NAME and EMAIL from 2 tables and send a predefinite number of emails per hour.

    So my first problem is taking the emails
    I know how to make the query, the thing is that the TO: where I send the email must be: Name <email>.

    But the NAME is different in the 2 tables, so I have to "unite them in the same variabile.

    On the first table I have:
    - Denumire
    - Email 1
    - Email 2

    On the seccond table I have:
    - Name
    - Email

    A friend of mine sugested to use foreach to send emails to each email. Pretty logical.

    But my main problem is how to only send 100 emails per HOUR? How should I approach this?

    Thanks.
     
    PET, Mar 21, 2007 IP
  2. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is there a reason we should know about as to why you don't want to use phplist? No need really to re-invent the wheel as they make it quite round.
     
    ErectADirectory, Mar 21, 2007 IP
  3. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Try PHPMailer, I have been using it for newsletters for a long time and it works great.

    As for the emails per hour thing, use CRON
     
    Houdas, Mar 21, 2007 IP
  4. PET

    PET Member

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #4
    I will try to use PHPMailer, but how to do the CRON job?
     
    PET, Mar 21, 2007 IP
  5. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    See more here - http://en.wikipedia.org/wiki/Crontab
    CRON basically schedules your scripts to launch periodically at given time. So if you want to send 500 emails every hour, you write the script that sends out 500 emails and then put it into CRON table to launch every hour.
     
    Houdas, Mar 21, 2007 IP
  6. itrana123

    itrana123 Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanx Houdas for informing abouth the CRONTAB i dont really need this right now but i think it will be very usefull in the future. Thanx again
     
    itrana123, Mar 21, 2007 IP
  7. PET

    PET Member

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #7
    I understand that, the thing is how do I know how on what emails have been send.
    For exemple:

    I send emails to email1, email2, email3.

    Next hour how do I know that I msut start from email4?
     
    PET, Mar 21, 2007 IP
  8. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    To every e-mail in your database table, you add a column "sent" - it could be a number - before the whole sending starts, you just set sent to 0, and then for every email sent, you set it to one:

    Quick&dirty code:

    
    $res = mysql_query("SELECT * FROM emails WHERE sent=0");
    while($email = mysql_fetch_assoc($res)) {
     mail(....) // send the mail
     mysql_query("UPDATE emails SET sent=1 WHERE email=$email['email']");
    }
    
    PHP:
     
    Houdas, Mar 21, 2007 IP
  9. PET

    PET Member

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #9
    I see your point, the thing is that my emails are on other tables, not in a "designed" table especialy for emails.

    EDIT: nevermind, i see your point :)

    my problem is how do I create that cron job? Never used it before, I mean...code it but I have used some cron jobs in vBulletin.
     
    PET, Mar 21, 2007 IP