I want to write some mails from a database to a txt

Discussion in 'PHP' started by G-hamsteR, Mar 16, 2009.

  1. #1
    Hello.

    I have a database with many columns, like username, password etc. One of these is 'email'.

    I want each time a new user is added to the database, the mail to be added to a txt file.

    All in all, i want to have all the e-mails in a txt file one under the other. The txt file should be updated and rewrited every time a new mail is added.


    Is it possible?

    Thanks,
    G-hamsteR
     
    G-hamsteR, Mar 16, 2009 IP
  2. mystxx

    mystxx Active Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #2
    Let's say the file you want your e-mails in is called emails.txt and e-mail is in variable $email
    Then you should do the following to add that e-mail to emailst.txt in a new line:

    $email=$email."\n";
    $fp=fopen("emails.txt","a");
    fwrite($fp,$email,strlen($email));
    fclose($fp);

    You should set the right permissions for the file - give the script the right to write in it.
     
    mystxx, Mar 16, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Admittedly, I don't know your specific use case, but wouldn't it be easier to just have the text listing of email addresses created on demand?
     
    SmallPotatoes, Mar 16, 2009 IP
  4. G-hamsteR

    G-hamsteR Well-Known Member

    Messages:
    268
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Thanks a lot!
     
    G-hamsteR, Mar 16, 2009 IP