Function mail()

Discussion in 'PHP' started by amii, Jun 17, 2009.

  1. #1
    This script should send e-mails, which are getting form text file mail.txt and it does it. However I want to do soemthing else, the script should send 10 e-mails after first running. Afterwards, it should should start sending e-mails from 11 to 21 on the list and so on.
    In the file plik.txt the number of sending e-mails is saved, but i dont know how to force the script to sending e-mails from $i e-mail on the list.
    Any help?

    <?php
    $subject = 'topic';
    $message = 'some text';
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
        
        $key=file('mail.txt');  // text file with the e-mail list
        foreach ($key as $value) {
        mail($value, $subject, $message, $headers);  
        if(mail)
        {
        $i++;
        }
      }
        
        $fp=fopen('plik.txt', 'w+');
        fwrite($fp, $i);
        fclose($fp);
        echo $i;   // the numebr of sending e-mails
      
    ?>
    PHP:
     
    amii, Jun 17, 2009 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    May I ask why you would want to split the mailings into groups of 10? You will still have to loop through each 10 to send them individually.

    You can do it by putting the information to send in an array to send later. Based on what you've already coded this shouldn't be too difficult for you.
     
    Weirfire, Jun 17, 2009 IP
  3. amii

    amii Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This script should start from CRON. Asking about your question, it is server matter. The server doesnt allow me to send more than, let's say 100 e-mail. The second reason is time. On my server i have 30 seconds allowed for scripts execution which for sure will be exceed.
     
    amii, Jun 17, 2009 IP
  4. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #4
    May I know, how your .txt file contains the emails? I mean, how emails are separated from each other in the file?
     
    techbongo, Jun 17, 2009 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Why dont you increase your max execution time on your server settings or PHP.INI?
     
    Weirfire, Jun 17, 2009 IP
  6. matt_fawcett

    matt_fawcett Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You could check the file that you write to, to see where the script last got to. Really the best way would be to store everything in a database table. You could then have a column called 'sent' and whenever you sent that message you set that column flag to true. The next time your script runs it only retrieves rows that have not been sent yet.
     
    matt_fawcett, Jun 17, 2009 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    I'm liking your idea Matt. Very tidy! :)
     
    Weirfire, Jun 17, 2009 IP
  8. amii

    amii Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I dont have permission to do it.

    Each e-mail in the .txt file is in the new line. It looks like this...
    
    email1@.blblbl.com
    email2@.blblbl.com
    email3@.blblbl.com
    
    PHP:
    So, the question is how to do it:D
     
    amii, Jun 17, 2009 IP
  9. maestria

    maestria Well-Known Member

    Messages:
    705
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #9
    Copy the complete emails into a text file and use that as the feeder. Send the email to first 10 or 100 email address. Delete them from the file and repeat the procedure in a loop. You may put a sleep in between or else there is a chance that your host/DC may block your Space/Server as potential spammer.
     
    maestria, Jun 18, 2009 IP
  10. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #10
    You may have hit a little close to the bone there... ;)
     
    Weirfire, Jun 18, 2009 IP
  11. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #11
    Ah - I'm looking for a similar thing - what a great idea!

    Add a new column in my table called sent and set it to either 'y' or 'n'.

    use something like
    sql(SELECT email, name FROM mailList WHERE sent='n' LIMIT='10')
    for each
    mail()
    set sent to y
    next
    PHP:
    run on a cron job every day - and then you could add in an if statement that says something like:
    if number of record = 0 then set all 'sent' to 'n'
    PHP:

    That way, it would send a block of 10 each day, and when it has run out, it will start the whole process again!


    Not the best or nicest solution ever, but it does get round all the above problems.

    If you need a hand writing the PHP or building the MySQL DB for this, give me a shout... I've used really crude scripting here cause I'm in a rush!


    Take it easy,

    Andrew


    EDIT: In real life - my mind works like that! It all makes sense to me- let me know if you need clarification!
     
    aquasonic, Jun 18, 2009 IP