February 05, 2014

February 05, 2014
In this article, we are going to discuss about how to create POP3 filter in PHP using Zend Framework. POP3 is nothing but Post Office Protocol (POP) is an application-layer Internet standard protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP connection. It is mostly used to send and receive an Email in an application. I'm going to explain about how to create POP3 filter in php using Zend framework.

Create a file in the server named "pop3filter.php" and add the below codes in that file.

<?php
require_once 'Zend/Mail/Storage/Pop3.php';

$spammers = array(
    "email1@example.com",
    "email2@example.com",
);

$mail = new Zend_Mail_Storage_Pop3(array('host' => 'pop3.example.com', 'user' => 'john.doe@example.com', 'password' => 'example', 'port' => 110));

echo $mail->countMessages() . " messages found\n";

foreach ($mail as $messageId => $message) {
  echo "{$messageId} : Mail from '{$message->from}': {$message->subject}\n";

  if(in_array(strtolower($message->from), $spammers, true)) {
    $mail->removeMessage($messageId);
    echo "Message removed\n";
  }
}

?>

Crontab

$ crontab -e
# m h  dom mon dow   command
*/10 * * * * /usr/bin/php /home/john/bin/pop3filter/pop3filter.php > /dev/null 2>&1

0 comments:

Post a Comment