search
HomeBackend DevelopmentPHP Tutorialphp如何验证smtp信息的正确

最近在用dede做站,看到后台有启用smtp方式发送邮件的设置,但没有验证。请问各位PHP大神,如何验证填写的smtp信息是否正确,验证包括端口、用户名、密码?求php代码实现,并输出这些错误信息,100分奉上!感谢。


回复讨论(解决方案)

dede的启用smtp方式发送邮件的设置,你是安装的插件吗?
我本地装的最新dede好像没这个功能设置哦

回楼上大牛,我只要能验证smtp信息是否正确就行,不需要做成dede插件。

//打开smtp服务器端口
$fp = @fsockopen($smtp_host, 25);
if (!$fp)
echo "Error: Cannot conect to ".$smtp_host."
";

$smtp = array(	//1、EHLO,期待返回220或者250	array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),	//2、发送Auth Login,期待返回334	array("AUTH LOGIN".$lb,"334","AUTH error:"),	//3、发送经过Base64编码的用户名,期待返回334	array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "),	//4、发送经过Base64编码的密码,期待返回235	array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : ")	);		//5、发送Mail From,期待返回250	$smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: ");	//6、发送Rcpt To。期待返回250	$smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: ");	//7、发送DATA,期待返回354	$smtp[] = array("DATA".$lb,"354","DATA error: ");	//8.0、发送From	$smtp[] = array("From: ".$from.$lb,"","");	//8.2、发送To	$smtp[] = array("To: ".$to.$lb,"","");	//8.1、发送标题	$smtp[] = array("Subject: ".$subject.$lb,"","");$result_str="";	//发送smtp数组中的命令/数据	foreach($smtp as $req)	{	//发送信息	@fputs($fp, $req[0]);	//如果需要接收服务器返回信息,则	if($req[1])	{	//接收信息	while($result = @fgets($fp, 1024))	{	if(substr($result,3,1) == " ")	{	break;	}	};	if (!strstr($req[1],substr($result,0,3)))	{	$result_str.=$req[2].$result."<br>";	}	}	}	//关闭连接	@fclose($fp);	return $result_str;	}

倒没有没弄过验证smtp的端口、用户名、密码,端口还好说,但用户名、密码的话,只能尝试去请求来判断了...

function smtp_sockopen_relay() 

$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); 
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); 
if (!($this->sock && $this->smtp_ok())) 

$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); 
$this->log_write("Error: ".$errstr." (".$errno.")\n"); 
return FALSE; 

$this->log_write("Connected to relay host ".$this->relay_host."\n"); 
return TRUE;; 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Framework Security Features: Protecting against vulnerabilities.Framework Security Features: Protecting against vulnerabilities.Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)