Mit PHP - Thunderbird Mail-Adressen Auslesen

  • Hallo, ich bin neu hier und noch zimmlicher Anfänger in PHP!

    Mein Problem ist:
    ich hab ein kleines php-script geschrieben um aus einer Datei bestimmte "nur" Mailadressen auszulesen und zu einer textdatei zu exportieren, nun werden die einträge jedoch doppelt angezeigt und geschrieben. Die Datei ist ein export aus einem thunderbird ordner (Thunderbird Datei).

    Kann mir wer helfen und das Skript verbessern und hier Posten?

    Währe dringend!

    Danke

    P.S.
    Vielleicht kann man sonst noch was verbessern z.b. leerzeilen entfernen und ich bin nicht sicher ob alle mailadressen ausgelesen werde!

    Script:
    ---------------------------------------------------------------------------------------------------------------
    <?php

    // DATEIN AUSLESEN
    $fp = fopen("export.txt","r+");

    // IN DIESE DATEI SPEICHERN
    $fp2 = fopen("datei.txt","w+");// Datei erstelllen, wenn nicht vorhanden

    // AUSZULASSENDE MAIL-ADRESSEN
    $lookFor1 = 'info@localhost.com';
    $lookFor2 = 'MAILER-DAEMON@localhost.net';
    $lookFor3 = '@newsletter.localhost.com';

    $replacement = '';


    if ($fp)
    {
    while(!feof($fp))
    {

    $text = fgets($fp,1000);

    $text = preg_replace('/'.$lookFor1.'/', $replacement, $text).'<br />';
    $text = preg_replace('/'.$lookFor2.'/', $replacement, $text).'<br />';
    $text = preg_replace('/'.$lookFor3.'/', $replacement, $text).'<br />';


    preg_match_all('/[A-Z0-9._%-]+@[A-Z0-9-]+.[A-Z]{2,4}+.[A-Z]{2,4}+.[A-Z]{2,4}/i', $text, $erg, PREG_SET_ORDER);

    foreach ($erg as $wert) {

    // DATEN AUSGABE IN DATEI
    $ausgabe = "\n" . $wert[0] . "\n";

    fputs($fp2,"$ausgabe"); // Daten werden jetzt mit fputs in die txt Datei angehängt. OK!!


    // DATEN AUSGABE AM BILDSCHIRM
    echo "<br>" . $wert[0] . "<br>";


    }

    }
    }
    fclose($fp);


    ?>
    ---------------------------------------------------------------------------------------------------------------


    DATEI export.txt:
    ---------------------------------------------------------------------------------------------------------------
    From - Thu Dec 23 18:27:57 2010
    X-Account-Key: account7
    X-UIDL: UID47284-1275131142
    X-Mozilla-Status: 0000
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Received: (qmail 3245 invoked for bounce); 20 Dec 2010 03:54:53 +0100
    Date: 20 Dec 2010 03:54:53 +0100
    From: MAILER-DAEMON@localhost.net
    To: info@localhost.com
    Subject: failure notice

    Hi. This is the qmail-send program at localhost.net.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.

    <scswete@bellsouth.net>:
    Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)
    I'm not going to try again; this message has been in the queue too long.

    --- Below this line is a copy of the message.

    Return-Path: <info@localhost.com>
    Received: (qmail 10181 invoked from network); 12 Dec 2010 22:06:50 +0100
    Received: from testsite.com (HELO newsletter.localhost.com) (84.19.182.113)
    by kaltlicht.com with SMTP; 12 Dec 2010 22:06:50 +0100
    Date: Sun, 12 Dec 2010 22:06:50 +0100
    Return-Path: info@localhost.com
    X-Sender: info@localhost.com
    Errors-To: info@localhost.com
    To: scswete@bellsouth.net
    From: Testmail <info@localhost.com>
    Reply-to: Testmail <info@localhost.com>
    Subject: Testsubject
    Message-ID: <2f850b34125bce94234a3ea24c6189b7@newsletter.localhost.com>
    X-Priority: 3
    X-Mailer: Mailer
    X-Mailer-MsgId: c2Nzd2V0ZUBiZWxsc291dGgubmV0
    X-Mailer-CSID: MV8x
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="iso-8859-1"

    <html dir="ltr">
    <head>
    </head>
    <body>

    Mailtext

    </body>
    </html>


    From - Thu Dec 23 18:27:57 2010
    X-Account-Key: account7
    X-UIDL: UID47285-1275131142
    X-Mozilla-Status: 0000
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Received: (qmail 3289 invoked for bounce); 20 Dec 2010 03:54:56 +0100
    Date: 20 Dec 2010 03:54:56 +0100
    From: MAILER-DAEMON@localhost.net
    To: info@localhost.com
    Subject: failure notice

    Hi. This is the qmail-send program at localhost.net.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.

    <bdavis04@bellsouth.net>:
    Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)
    I'm not going to try again; this message has been in the queue too long.

    --- Below this line is a copy of the message.

    Return-Path: <info@localhost.com>
    Received: (qmail 11382 invoked from network); 12 Dec 2010 22:06:53 +0100
    Received: from testsite.com (HELO newsletter.localhost.com) (84.19.182.113)
    by kaltlicht.com with SMTP; 12 Dec 2010 22:06:53 +0100
    Date: Sun, 12 Dec 2010 22:06:53 +0100
    Return-Path: info@localhost.com
    X-Sender: info@localhost.com
    Errors-To: info@localhost.com
    To: bdavis04@bellsouth.net
    From: Testmail <info@localhost.com>
    Reply-to: Testmail <info@localhost.com>
    Subject: Testsubject
    Message-ID: <e08dccc90323a4144e789bc30349d148@newsletter.localhost.com>
    X-Priority: 3
    X-Mailer: Mailer
    X-Mailer-MsgId: YmRhdmlzMDRAYmVsbHNvdXRoLm5ldA==
    X-Mailer-CSID: MV8x
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="iso-8859-1"

    <html dir="ltr">
    <head>
    </head>
    <body>

    Mailtext

    </body>
    </html>

    From - Thu Dec 23 18:27:58 2010
    X-Account-Key: account7
    X-UIDL: UID47286-1275131142
    X-Mozilla-Status: 0000
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Received: (qmail 3296 invoked for bounce); 20 Dec 2010 03:54:59 +0100
    Date: 20 Dec 2010 03:54:59 +0100
    From: MAILER-DAEMON@localhost.net
    To: info@localhost.com
    Subject: failure notice

    Hi. This is the qmail-send program at localhost.net.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.

    <llhl@aristotle.net>:
    Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)
    I'm not going to try again; this message has been in the queue too long.

    --- Below this line is a copy of the message.

    Return-Path: <info@localhost.com>
    Received: (qmail 11596 invoked from network); 12 Dec 2010 22:06:56 +0100
    Received: from testsite.com (HELO newsletter.localhost.com) (84.19.182.113)
    by esser-transporte.at with SMTP; 12 Dec 2010 22:06:55 +0100
    Date: Sun, 12 Dec 2010 22:06:55 +0100
    Return-Path: info@localhost.com
    X-Sender: info@localhost.com
    Errors-To: info@localhost.com
    To: llhl@aristotle.net
    From: Testmail <info@localhost.com>
    Reply-to: Testmail <info@localhost.com>
    Subject: Testsubject
    Message-ID: <4625f7b77ab9af72b21b5f7aeefdeaa3@newsletter.localhost.com>
    X-Priority: 3
    X-Mailer: Mailer
    X-Mailer-MsgId: bGxobEBhcmlzdG90bGUubmV0
    X-Mailer-CSID: MV8x
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="iso-8859-1"

    <html dir="ltr">
    <head>
    </head>
    <body>

    Mailtext

    </body>
    </html>


    From - Thu Dec 23 18:27:59 2010
    X-Account-Key: account7
    X-UIDL: UID47287-1275131142
    X-Mozilla-Status: 0000
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Received: (qmail 3337 invoked for bounce); 20 Dec 2010 03:55:03 +0100
    Date: 20 Dec 2010 03:55:03 +0100
    From: MAILER-DAEMON@localhost.net
    To: info@localhost.com
    Subject: failure notice

    Hi. This is the qmail-send program at localhost.net.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.

    <pgleaton@bellsouth.net>:
    Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)
    I'm not going to try again; this message has been in the queue too long.

    --- Below this line is a copy of the message.

    Return-Path: <info@localhost.com>
    Received: (qmail 11943 invoked from network); 12 Dec 2010 22:07:01 +0100
    Received: from testsite.com (HELO newsletter.localhost.com) (84.19.182.113)
    by cafe-parterre.at with SMTP; 12 Dec 2010 22:07:01 +0100
    Date: Sun, 12 Dec 2010 22:07:01 +0100
    Return-Path: info@localhost.com
    X-Sender: info@localhost.com
    Errors-To: info@localhost.com
    To: pgleaton@bellsouth.net
    From: Testmail <info@localhost.com>
    Reply-to: Testmail <info@localhost.com>
    Subject: Testsubject
    Message-ID: <85da28f992d1489f89944c68cae9a899@newsletter.localhost.com>
    X-Priority: 3
    X-Mailer: Mailer
    X-Mailer-MsgId: cGdsZWF0b25AYmVsbHNvdXRoLm5ldA==
    X-Mailer-CSID: MV8x
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="iso-8859-1"

    <html dir="ltr">
    <head>
    </head>
    <body>

    Mailtext

    </body>
    </html>


    ---------------------------------------------------------------------------------------------------------------

    4 Mal editiert, zuletzt von mtito (2. Januar 2011 um 18:05)

  • Ich machs nicht gerne, aber erstemal gibts Mecker:

    1. Das Posten von Mail-adresswen ist hier nicht gestattet. Zudem sind die Leute, dessen Adreswsen du hier veröffentlichst darüber evtl. nicht erfreut.
    2. Nutze bitte die PHP-/ und Code-Tags des Forums, das erleichtert das Lesen ungemein.
    3. Dringend ist für dich, nicht für uns.

    Nun zu deinem Problem. Die Mailadressen kommen nun mal doppelt im Export-script vor. Lege dir in deinem Script ein Array an, welches sich merkt, welche Mails schon mal vorgekommen sind. Dann chekcst du das Array vor dem Eintragen in die Datei


  • Hallo jojo87!

    Also:
    1.) zu denn Mailadressen "die gibt es alle nicht real" und genau deshalb lese ich sie aus!
    2.) Ich muß mich erst im Forum einarbeiten, weiß nicht wo die Tags sind!
    3.) Ich brauch hilfe und nicht Belehrungen zum Forum ;)

    P.S.
    DEIN TEXT ZITAT:
    Nun zu deinem Problem. Die Mailadressen kommen nun mal doppelt im Export-script vor. Lege dir in deinem Script ein Array an, welches sich merkt, welche Mails schon mal vorgekommen sind. Dann chekcst du das Array vor dem Eintragen in die Datei
    ANTWORT!!!
    Wenn ich wüste wie ich die Arrays auslese und die Doppelten Einträge entferne würd ich nicht hier schreiben!


    Danke!

  • ich machs nicht gerne, aber erstemal gibts mecker:

    1. Das posten von mail-adresswen ist hier nicht gestattet. Zudem sind die leute, dessen adreswsen du hier veröffentlichst darüber evtl. Nicht erfreut.
    2. Nutze bitte die php-/ und code-tags des forums, das erleichtert das lesen ungemein.
    3. Dringend ist für dich, nicht für uns.

    Nun zu deinem problem. Die mailadressen kommen nun mal doppelt im export-script vor. Lege dir in deinem script ein array an, welches sich merkt, welche mails schon mal vorgekommen sind. Dann chekcst du das array vor dem eintragen in die datei

    sicher kannst mir dann auch die lösung posten, für denn belehrungstext hattest ja auch zeit!!!

  • Zitat


    Also:
    2.) Ich muß mich erst im Forum einarbeiten, weiß nicht wo die Tags sind!

    Und das ist also ein Grund, sie wieder zu entfernen, wenn ich mir schon die Mühe mache sie für ich einzufügen?

    Zitat


    3.) Ich brauch hilfe und nicht Belehrungen zum Forum

    Die "Belehrung" soll Hilfestellung für dich sein, um in diesem Forum Posts zu verfassen, die andere dazu animiert dir zu helfen. Überlegs dir.
    Zudem habe ich versucht dir Hilfestellung zu geben. Da du sagst, das obige Script selbst erstellt zu haben, kann ma davon ausgehen, dass du schon mal wqas von nem Array gehört hast. Schliesslich benutzt dus ja oben schon.
    Folgende Funktion brauchst du:
    http://php.net/in_array

    Wenns dir nur darum geht, ne fertige Lösung abzugreifen, verschieb ich den Thread ins Job-Forum. Dann solltest du dir eine passende Gegenleistung überlegen.
    Ansonsten gilt: Hier gibt es Hilfe zur Selbsthilfe, wir sind keine Codemaschine


  • sicher kannst mir dann auch die lösung posten, für denn belehrungstext hattest ja auch zeit!!!


    Geiler Neueinstieg in ein Forum. Hut ab, habe ich so noch nie gelesen.

    Bei deiner Frechheit, die du hier an den Tag legst, denke ich wird dein Problem deines bleiben.

    Erfolgreiches neues Jahr...:rolleyes:

    Niemals provozieren lassen, jeder darf seine Meinung haben.