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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: mail queue

  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Exclamation mail queue

    i am creating an e newsletter application and want a mail queue.

    how would this be done.

    eg.

    the mail has to be sent to 300 people it list who is left to send it to.

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    When you are ready to send your emails have your script create a stack or que of emails maybe as a sql table or something. If the table had a sent flag field then when a email is sent the sent flag for that record can be set to true. the stack/que should not be dropped until all the sent lags are set to true

    P.s I strongly recommend using a cron job for this.
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    im sorry im a bit slow.

    What!

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    have you done a SQL databse before?
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    yes all of the email addresses are stored in one and user ifo for the app it sored in anouther table with MD5 encription!

  • #6
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Ok try to turn the members table into a mailing list. Simply add an extra flag to confirm that user wishes to recieve mail. Then your script should run a query that selects all users with the recieve mail flag set to true. Once is has these records it should write them (or their key) to the stack. If you are intending to send all 300 emails in one sitting then it is exceptable to use an array. Then you can go through the stack one by one as you send an email remove it from the stack. Repeat until the stack is empty
    You can not say you know how to do something, until you can teach it to someone else.

  • #7
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Ok!

    I will try!

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    If you are intending to send all 300 emails in one sitting then it is exceptable to use an array.
    I would advise against having a script sit there for several minutes not providing any feedback, with the possibility of timing out (most likely).

    Instead, create a temporary table that holds all of the email addresses, or keep an array in a session variable.

    Have a page that refreshes itself after 1 second, every time the page loads, send the next X emails (X depends on the hosting server's processing power, to be safe you could do like 10). Then take those off of the list.

    You can even display a progress bar so the user knows how far it is done.

    And the only limit to the size would be the session data/temporary table size limit.

  • #9
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    rite i am quite new to php
    this is how it sends the email:

    PHP Code:
    <?php

    require_once('Connections/DreamMailer_db.php');
    include(
    'version/info.php');


    $subject $_POST['sub'];
    $message $_POST['mess'];
    $fromEmail "".$from."";

    // sql: select email address
    $sql "SELECT info.Email FROM info";
    $result mysql_query($sql);
    if (!
    $result){echo("Error performing query: " mysql_error() . "");}

    while (
    $query_data mysql_fetch_array($r esult))
    {
    mail ($query_data['Email'], "".$subject."""".$message."""From: ".$fromEmail);
    // end while

    ?>
    so

    i want to create another page with a queue on it and i have tried to do it the way you guys said. but failed miserably. so if someone could point me in the right direction. that would be great. its not that they don't work its just i have no clue on how to do them!

  • #10
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    So taking aedrins' advice we wil store them in a sql stack. First create a database table called email_stack with two fields; Email and Sent make sure that sent is default to false; Also remember to add the extra recieve_mail feild to the info table

    PHP Code:
    <?php

    require_once('Connections/DreamMailer_db.php');
    include(
    'version/info.php');
     

    $subject $_POST['sub'];
    $message $_POST['mess'];
    $fromEmail "".$from."";

    // sql: select email address
    $sql "SELECT * FROM info";
    $result mysql_query($sql);
    if (!
    $result){echo("Error performing query: " mysql_error() . "");}

    while (
    $query_data mysql_fetch_array($result))
    {
     
    $email=$query_data['Email'];
     
    $onlist=$query_data['recieve_mail'];// If this is true
     
    if($onlist=true){
        
    $q 'INSERT INTO email_stack (Email) VALUES ('.$email.')';
        
    $res mysql_query($q)OR die(mysql_error());
     }


    // So far we have made a list of emails to send it to. The script below shows how you can itterate through your stack and send the email.

    // sql: select email address
    $sql "SELECT * FROM email_stack";
    $result mysql_query($sql);
    if (!
    $result){echo("Error performing query: " mysql_error() . "");}

    while (
    $query_data mysql_fetch_array($result))
    {
      
    $email=$query_data['Email'];
      
    mail ($email"".$subject."""".$message."""From:  ".$fromEmail); 
      
    $sql='UPDATE email_stack
    SET Sent = 1
    WHERE Email = '
    .$email;
    }



    ?>
    You can not say you know how to do something, until you can teach it to someone else.

  • #11
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    timgolding, when you're posting code for someone, you don't have to add in all the error checking. This is something they can implement themselves, and it will only make it harder to read.

    setup.php
    PHP Code:
    $result query("SELECT * FROM users WHERE send_mail = 1");
    $emails = array();
    while (
    $row get_row($result)) {
        
    $emails[] = $row['email'];
    }

    query("INSERT INTO mail_stack(email) VALUES('" implode("'), ('"$emails) . "')"
    mail.php
    PHP Code:
    $result query("SELECT * FROM mail_stack WHERE sent = 0");

    if (
    num_rows($result)) {
        
    $emails = array();
        while (
    $row get_row($result)) {
            
    mail($row['email'], $subject$body$headers);
            
    $emails[] = $row['email'];
        }
        
        
    query("UPDATE mail_stack SET sent = 1 WHERE email IN ('" implode("', '"$emails) . "')");


  • #12
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    what should be the default value of mail-stack?

  • #13
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    What default value? The example we gave is a database implementation. It would be an empty table.

  • #14
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    i really dont get any of this.?.?

  • #15
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Then perhaps you need to learn some more basic PHP. As this is quite basic stuff.

    Perhaps that is why your advice is usually not helping the question.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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