我编写代码来从不同的服务器(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,但它不起作用。