check SMTP authentication without sending email and without using pear in PHP(在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证)
本文介绍了在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不发送邮件和不使用PHP中使用PEAR的情况下检查SMTP身份验证。他们有什么方法可以检查主机、端口、用户名和密码的身份验证吗?
我查看了SWIFTMAILLER,它显示正在发送电子邮件进行身份验证。 http://swiftmailer.org/docs/sending.html#smtp-with-a-username-and-password
phpmaeller上也是如此。 https://github.com/PHPMailer/PHPMailer/blob/master/examples/smtp.phps
推荐答案
诚然,这不是最干净的解决方案,但它会奏效。下面复制了一个expect
脚本,该脚本将连接到SMTP服务器,尝试进行身份验证,然后退出会话并断开连接。如果expect
脚本的最后一行输出是235 2.7.0 Authentication successful
(或响应代码以2xx开头的另一个类似响应),则使用提供的凭据验证成功,否则验证失败。您可以使用shell_exec()
从您的PHP脚本调用此expect
脚本,并分析输出以测试是否可以在给定一组凭据的情况下使用SMTP服务器进行身份验证。
#!/usr/bin/expect
set mailserver "smtp.smtpserver.com"; #fqdn of SMTP server
set credentials "AG1xxxxxxxxxxxxxxxxxxxDNy"; #this string should be " username password" base64-encoded.
spawn telnet $mailserver 25
expect "failed" {
send_user "$mailserver: connect failed
"
exit
} "2?? *" {
} "4?? *" {
exit
} "refused" {
send_user "$mailserver: connect refused
"
exit
} "closed" {
send_user "$mailserver: connect closed
"
exit
} timeout {
send_user "$mailserver: connect to port 25 timeout
"
exit
}
send "HELO foo.com
"
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "AUTH PLAIN $credentials
";
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "QUIT
"
exit
这篇关于在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证


猜你喜欢
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01