title: Fetch emails from email servers in php
body: <p>I write code to fetch emails from different servers (Gmail,yahoo,hotmail etc).I tested my code on gmail server and it worked, but for yahoo that code doesn't work.My code is :</p>
  
  <pre><code>$data array will be like 
  
  $data['type'] = 'pop3 or imap';
  $data['protocol_type'] = 'ssl or tls or none';
  $data['port'] = '993 or 995';
  $data['login_name'] = 'user name';
  $data['password'] = 'user password';
  public function testconnectionAction()
      {
  
          $data = $_POST;
  
  
          if($data['type'] == 'pop3' &amp;&amp; $data['protocol_type'] == 'none')
          {
                 $hostname = '{'.$data['host'].':'.$data['port'].'/pop3}INBOX';
               $username = $data['login_name'];
                $password = $data['password'];
              $imap = imap_open($hostname,$username,$password)or die(imap_last_error());
  
              if (!imap_ping($imap)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
          }elseif($data['type'] == 'imap' &amp;&amp; $data['protocol_type'] == 'none') {
               $hostname = '{'.$data['host'].':'.$data['port'].'}INBOX';
               $username = $data['login_name'];
                $password = $data['password'];
              $imap = imap_open($hostname,$username,$password);
              if (!imap_ping($imap)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
          }
        if($data['type'] == 'pop3' &amp;&amp; $data['protocol_type'] == 'ssl')
        {
               $hostname = '{'.$data['host'].':'.$data['port'].'/pop3/ss}INBOX';
               $username = $data['login_name'];
               $password = $data['password'];
              $imap = imap_open($hostname,$username,$password);
        //  
              if (!imap_ping($imap)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
        }
        if($data['type'] == 'imap' &amp;&amp; $data['protocol_type'] == 'ssl')
        {
          $hostname = '{'.$data['host'].':'.$data['port'].'/imap/ssl/novalidate-cert}INBOX';
          $username = $data['login_name'];
          $password = $data['password'];
  
  /* try to connect */
          $inbox = imap_open($hostname,$username,$password);
  
              if (!imap_ping($inbox)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
        }
  
         if($data['type'] == 'pop3' &amp;&amp; $data['protocol_type'] == 'tls')
        {
               $hostname = '{'.$data['host'].':'.$data['port'].'/pop3/tls}INBOX';
               $username = $data['login_name'];
               $password = $data['password'];
               $imap = imap_open($hostname,$username,$password)or die(imap_last_error());
              if (!imap_ping($imap)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
        }
        if($data['type'] == 'imap' &amp;&amp; $data['protocol_type'] == 'tls')
        {
          $hostname = '{'.$data['host'].':'.$data['port'].'/imap/tls}INBOX';
               $username = $data['login_name'];
               $password = $data['password'];
               $imap = imap_open($hostname,$username,$password);
  
              if (!imap_ping($imap)) {
                  echo "Test Failed.";
                  }else{
                        echo "Test Successfull.";
                  }
        }
  
      }
  </code></pre>
  
  <p>How can i test that code work on yahoo or not.i try to enter pop.yahoo.com for host and port 995 but it didn't work.</p>