PHP site that shows all emails sent to domain

Discussion in 'PHP' started by Pryda, Jun 15, 2007.

  1. #1
    Hello,

    I was visiting some sites like spam.la and dodgeit.com and wondering how these sites are implemented. I often wonder how things are implemented and feel bad when I fail to understand it ;)

    I have no idea how one could link postfix and php so that all emails sent to a specific domain are shown. Can someone give me an idea on how to do this? Once I have the incoming email data, it's pretty easy to insert them in a MySQL database and display them.

    Thanks!
    Pryda
     
    Pryda, Jun 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You can use IMAP.
     
    nico_swd, Jun 15, 2007 IP
  3. Pryda

    Pryda Peon

    Messages:
    506
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks nico_swd, that's exactly what I was looking for :)

    +rep for you ;)
     
    Pryda, Jun 15, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I'm not too familiar with IMAP, but here's something I wrote. (Yes I was bored, lol)

    
    <?php
    
    error_reporting(E_ALL);
    
    $imap_host     = 'xxxxx.com';
    $imap_port     = 110;
    $imap_userid   = 'xxxx@xxxxx.com';
    $imap_password = 'xxxxxx';
    
    $imap = @imap_open("{{$imap_host}/pop3:{$imap_port}}INBOX", $imap_userid, $imap_password) OR die(imap_last_error());
    $status = imap_check($imap);
    
    $bgcolor1 = '#CCCCCC';
    $bgcolor2 = '#FFFFFF';
    
    if (isset($_GET['do'], $_GET['msgid']) AND $_GET['do'] == 'viewmsg')
    {
    	$_GET['msgid'] = intval($_GET['msgid']);
    	$structure = imap_fetchstructure($imap, $_GET['msgid']);
    	
    	if ($structure->type == 1 AND sizeof($structure->parts) == 0)
    	{
    		$body = imap_fetchbody($imap, $_GET['msgid'], 1);
    	}
    	else
    	{
    		$body = imap_body($imap, $_GET['msgid']);
    	}
    	
    	?>
            <pre>
        		<?php echo $body; ?>
    		</pre>
            
        <?php
    }
    else
    {
    	?>
        
        <table cellpadding="3">
        <tr style="font-weight: bold;">
            <td>#</td>
            <td>From</td>
            <td>Subject</td>
            <td>Date</td>
        </tr>
        
    	<?php
        
        if (!$status->Nmsgs)
        {
            ?>
            <tr>
                <td colspan="4">No messages found</td>
            </tr>
            <?php
        }
        else
        {
    		for ($i = 1; $i <= $status->Nmsgs; $i++)
    		{
    			if (!$msg = @imap_headerinfo($imap, $i))
    			{
    				continue;
    			}
    
    			if (!trim($msg->Subject))
    			{
    				$msg->Subject = '[No subject]';
    			}
                
                ?>
                <tr style="background-color: <?php echo $i % 2 == 0 ? $bgcolor1 : $bgcolor2; ?>;">
                    <td><?php echo $i; ?></td>
                    <td><?php echo htmlspecialchars($msg->fromaddress); ?></td>
                    <td><a href="?do=viewmsg&amp;msgid=<?php echo $i; ?>"><?php echo $msg->Subject; ?></a></td>
                    <td><?php echo $msg->Date; ?></td>
                </tr>
                <?php
            }	
        }
        
        ?>
        
        </table>
    <?php
    
    }
    
    imap_close($imap);
    
    ?>
    
    PHP:

    It's not perfect, but should get you started...
     
    nico_swd, Jun 15, 2007 IP
    krakjoe likes this.
  5. Pryda

    Pryda Peon

    Messages:
    506
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks again, you are very helpful!
     
    Pryda, Jun 15, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Nice nico, I started, but I just couldn't be bothered to finish, something shiny prolly caught my attention :D
     
    krakjoe, Jun 15, 2007 IP
    nico_swd likes this.
  7. Pryda

    Pryda Peon

    Messages:
    506
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I made a simple site with nico_swd's code, but it's rather slow. Are there any ways to speed it up, besides caching the entries in a mysql database?

    The site is here: http://spamplz.com/
     
    Pryda, Jun 22, 2007 IP