1

我编写代码来从不同的服务器(Gmail、雅虎、hotmail 等)获取电子邮件。我在 gmail 服务器上测试了我的代码并且它有效,但对于雅虎来说,该代码不起作用。我的代码是:

$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' && $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' && $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' && $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' && $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' && $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' && $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.";
                }
      }

    }

我如何测试该代码是否可以在 yahoo 上运行。我尝试输入 pop.yahoo.com 作为主机和端口 995,但它不起作用。

4

1 回答 1

0

经过搜索和测试,我找到了用于测试的 yahoo 电子邮件设置。

Incoming Server: imap.mail.yahoo.com Port 993 with SSL
Outgoing Server: smtp.bizmail.yahoo.com Port 465 with SSL (requires Authentication to be enabled)
Username: Your Business Email address (e.g. name@mycompany.com)
Password: Your Business Email password 

而对于 Hotmail,我使用以下代码:

Outlook.com Incoming Mail Server (POP3) - pop3.live.com (logon using Secure Password Authentication – SPA,SSL enabled mail server port: 995).Hope it help someone like me.
于 2013-09-12T07:01:25.470 回答