Hallo,
ich möchte E-Mails auslesen und die Daten in Variablen schreiben um sie dann weiter verarbeiten zu können.
Die E-Mail hat folgenden Aufbau und ist immer gleich:
Code
##ID:21.01.28.19.45.21
##DET:Tisch 5;36;3
##SP1:SYLVIA1956;373;6;0;913
##SP2:SKSVEN;108;6;3;378
##SP3:JOGIBAER3007;419;15;3;1139
Und mit folgendem Code lese ich die Mails aus. Dort wird der Inhalt der ersten Zeile nicht in die Variable geschrieben und in der Zeile 2 fehlt alles vor der 5 in der Variable.
PHP
<?php
error_reporting(E_ALL ^ E_NOTICE);
$msg = 1;
include "mail-erg-verbindung.inc";
$imapi = imap_check($mbox);
$result = imap_fetch_overview($mbox,"1:{$imapi->Nmsgs}",0);
foreach ($result as $overview)
{
// if(!stristr($overview->subject,'Ergebnisliste')) // Betreff darf den Text Spielergebnis nicht enthalten
if($overview->subject != 'Ergebnisliste') // Alle was nicht genau Spielergebnis ist
{
// Diese Nachricht wird gelöscht....
echo "#{$overview->msgno} ({$overview->subject}) - From: {$overview->from} {$overview->subject}\n";
imap_delete($mbox, $overview->msgno); // Löschen der Nachricht
imap_expunge($mbox);
}
}
$nmsg = $imapi->Nmsgs;
if ($nmsg == 0)
{
echo "Mailbox leer";
exit;
}
for ($msg = 1 ; $msg <= $nmsg; $msg++)
{
$header = imap_fetchheader($mbox, $msg);
if (preg_match('%boundary=(.*)%', $header, $boundary))
{
$boundary = $boundary[1];
if(substr($boundary, 0, 1) == '"') $boundary = substr($boundary, 1, -2);
}
else
$boundary = " ";
$body = imap_body($mbox, $msg);
$u = 0;
$mailparts = explode("$boundary", $body);
foreach ($mailparts as $content)
{
$u++;
if ($u== 2)
{
$content = trim($content);
$content = substr($content, 0, -2);
if (preg_match('%filename=(.*)%', $content, $fname))
{
$fname = $fname[1];
if (substr($fname, 0, 1) == '"') $fname = substr($fname, 1, -2);
}
if ($p = strpos($content, "\r\n\r\n"))
$content = trim(substr($content, $p));
echo "Mail Nr:".$msg;
auswerten ($fname, $content);
echo "<br><br>";
}
}
//imap_delete($mbox, $msg);
}
imap_expunge($mbox);
imap_close($mbox);
function auswerten($fname, $content)
{
$content = explode("\n", $content);
$zeile_0 = $content[0];
echo "<br>";
echo $zeile_0;
$zeile_1 = $content[1];
echo "<br>";
echo $zeile_1;
$zeile_2 = $content[2];
echo "<br>";
echo $zeile_2;
$zeile_3 = $content[3];
echo "<br>";
echo $zeile_3;
$zeile_4 = $content[4];
echo "<br>";
echo $zeile_4;
?>
Alles anzeigen
Wo muss ich den Hebel ansetzen damit alle Daten in die Variablen geschrieben werden?
LG Sven