Script zum fetchen von Mails

diggity

Erfahrenes Mitglied
Hallo!

Ist es möglich, mit PHP die Mails z.B. eines GMX-Accounts abzurufen?
Ich stell mir das so vor:

Code:
Mein Server	-->	PHP Script	-->	GMX-Server
			PHP Script	<--	_/

Man müsste praktisch den pop3-Server kontaktieren und ihn auf Mails überpfüfen.
 
Das ist zwar fuer IMAP, aber man braucht eh die IMAP-Funktionen um auf POP3 zuzugreifen.
PHP:
<?php
function checkbody($body,$struct)
{
	if ($struct->subtype!="PLAIN")
		{
			if ($struct->parts[0]->encoding==0)
				{
					$body=imap_utf7_decode($body);
				}
			if ($struct->parts[0]->encoding==3)
				{
					$body=imap_base64($body);
				}
			if ($struct->parts[0]->encoding==4)
				{
					$body=imap_qprint($body);
				}
		}
	else
		{
			if ($struct->encoding==0)
				{
					$body=imap_utf7_decode($body);
				}
			if ($struct->encoding==3)
				{
					$body=imap_base64($body);
				}
			if ($struct->encoding==4)
				{
					$body=imap_qprint($body);
				}
		}
	$body=nl2br(htmlentities($body));
	if ($struct->subtype=="MIXED")
		{
			for ($part=1;$part<count($struct->parts);$part++)
				{
					$body=str_replace("&lt;&lt;".$struct->parts[$part]->dparameters[0]->value."&gt;&gt;",'<a href="download-attachment.php?msgid='.$_GET['msgid'].'&amp;part='.$part.'">&lt;&lt;'.$struct->parts[$part]->dparameters[0]->value.'&gt;&gt;</a>',$body);
				}
		}
	return $body;
}
$mailbox="INBOX";
$username="";
$password="";
$mbox=imap_open("{localhost/norsh}".$mailbox,$username,$password);
echo "<html>";
echo "<body>";
if (isset($_GET['show']))
	{
		$struct=imap_fetchstructure($mbox,$_GET['show']);
		$header=imap_header($mbox,$_GET['show']);
/*ob_start();
var_dump($header);
$dump=ob_get_contents();
ob_end_clean();
echo nl2br($dump).'<hr>';*/
		$body=imap_fetchbody($mbox,$_GET['show'],1);
		$body=checkbody($body,$struct);
		echo $body;
	}
else
	{
		if (isset($_GET['delete']))
			{
				imap_delete($mbox,$_GET['delete']);
				imap_expunge($mbox);
			}
		$mboxinfo=imap_check($mbox);
//var_dump($mboxinfo);
		echo $mboxinfo->Nmsgs." eMails<br>";
		echo $mboxinfo->Recent." unread<br>";
		echo '<table border="1">';
		echo '<tr><th>From</th><th>Subject</th><th>Date</th><th>Action</th></tr>';
		for ($msgcount=1;$msgcount<=$mboxinfo->Nmsgs;$msgcount++)
			{
				echo '<tr>';
				$header=imap_header($mbox,$msgcount);
				echo '<td><a href="showmails.php?show='.trim($header->Msgno).'">';
				if (isset($header->from[0]->personal))
					{
						echo $header->from[0]->personal.' &lt;'.$header->from[0]->mailbox.'@'.$header->from[0]->host.'&gt;';
					}
				else
					{
						echo $header->from[0]->mailbox.'@'.$header->from[0]->host;
					}
				echo '</a></td>';
				echo '<td><a href="showmails.php?show='.trim($header->Msgno).'">'.$header->subject.'</a></td>';
				echo '<td><a href="showmails.php?show='.trim($header->Msgno).'">'.$header->date.'</a></td>';
				echo '<td><a href="showmails.php?delete='.trim($header->Msgno).'">Delete</a></td>';
				echo '</tr>';
			}
		echo '</table>';
	}
echo "</body>";
echo "</html>";
imap_close($mbox);
?>
 
Das scheint im Grunde das gleiche zu machen wie mein Script.
Nur das dies hier in 2 Scripts geteilt wurde (Mailbox-Ansicht/Mail-Ansicht) und ich beides zusammen hab.
Und das verlinkte ist halt direkt fuer POP3, aber ansonsten sieht's recht gleich aus.

Naja, mal sehen ob unser Freund sich mit froher Botschaft zurueckmeldet.
 
@reptiler
Das war mir soweit schon klar ;)
Wollte nur eine alternative Quelle angeben, ist immer besser mehrere Denkanstösse in unterschiedlichen Codeformen zu haben!
 
@Operator_Jon:
Natuerlich, da sag ich auch nix gegen.
Besonders wo das von Dir verlinkte Script ja auch gleich fuer POP3 geschrieben ist, im Gegensatz zu meinem, welches im Moment fuer IMAP geschrieben ist.
Das wird sich aber auch noch aendern, da das ganze mal Teil eines kompletten Webmailers werden soll.
 
Zurück