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>
---------------------------------------------------------------------------------------------------------------