actweb / mail-auth
邮件服务器身份验证类,允许使用或不用SSL对POP/IMAP/SMTP进行用户认证
0.5
2018-09-13 23:35 UTC
Requires
- monolog/monolog: 1.9.*
This package is auto-updated.
Last update: 2024-09-11 02:52:49 UTC
README
概述
PHP类,用于对邮件服务器进行用户认证。
规范
允许设置认证类型:POP3、POP3S、IMAP、IMAPS、SMTP、SMTPS。
接受用户名和密码,然后尝试登录指定的邮件服务器。
如果登录成功,则返回true,否则返回false。
SMTP认证功能改编自:http://support.webecs.com/kb/a390/php-mail-script-with-smtp-authentication.aspx
使用
设置日志记录,非必需,但有助于调试
$logger=new Logger('auth');
$logger->pushHandler(new StreamHandler(__DIR__.'/auth.log', LOGGER::DEBUG));
$logger->info('Auth Script Starting');
在调用authenticate()之后,你可以使用以下方式检查认证结果:
$result=$auth->authenticated;
SMTP认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MySMTPServerHostName');
$auth->setServerType('SMTP');
$auth->setSmtpLocalHost('MyLocalHostName');
$auth->setTimeOut(10);
$auth->setSslCheck(false);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();
SMTPS认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MySMTPServerHostName');
$auth->setServerType('SMTPS');
$auth->setSmtpLocalHost('MyLocalHostName');
$auth->setTimeOut(10);
$auth->setSslCheck(true);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();
POP3认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MyPOPServerHostName');
$auth->setServerType('POP3');
$auth->setSslCheck(false);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();
POP3S认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MyPOPServerHostName');
$auth->setServerType('POP3S');
$auth->setSslCheck(true);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();
IMAP认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MyIMAPServerHostName');
$auth->setServerType('IMAP');
$auth->setSslCheck(false);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();
IMAPS认证
$auth=new MailAuth($logger);
$auth->setMailServerUrl('MyIMAPServerHostName');
$auth->setServerType('IMAPS');
$auth->setSslCheck(true);
$auth->setUsername('MyUserName');
$auth->setPassword('MyPassword');
$result=$auth->authenticate();