代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
SMTP验证
作者:
Dezai.CN
/ 发布于
2011/6/11
/
465
<div><span style="color: rgb(0,0,0); font-weight: bold">function</span> mymail<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$to</span>,<span style="color: rgb(0,0,255)">$subject</span>,<span style="color: rgb(0,0,255)">$message</span>,<span style="color: rgb(0,0,255)">$headers</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <span style="font-style: italic; color: rgb(128,128,128)">// set as global variable</span> <a href="http://www.php.net/global" target="_blank"><span style="color: rgb(0,0,102)">global</span></a> <span style="color: rgb(0,0,255)">$GLOBAL</span>; <span style="font-style: italic; color: rgb(128,128,128)">// get From address</span> <span style="color: rgb(177,177,0)">if</span> <span style="color: rgb(102,204,102)">(</span> <a href="http://www.php.net/preg_match" target="_blank"><span style="color: rgb(0,0,102)">preg_match</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"/From:.*?[A-Za-z0-9<span style="color: rgb(0,0,153); font-weight: bold">\.</span>_%-]+<span style="color: rgb(0,0,153); font-weight: bold">\@</span>[A-Za-z0-9<span style="color: rgb(0,0,153); font-weight: bold">\.</span>_%-]+.*/"</span>, <span style="color: rgb(0,0,255)">$headers</span>, <span style="color: rgb(0,0,255)">$froms</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <a href="http://www.php.net/preg_match" target="_blank"><span style="color: rgb(0,0,102)">preg_match</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"/[A-Za-z0-9<span style="color: rgb(0,0,153); font-weight: bold">\.</span>_%-]+<span style="color: rgb(0,0,153); font-weight: bold">\@</span>[A-Za-z0-9<span style="color: rgb(0,0,153); font-weight: bold">\.</span>_%-]+/"</span>, <span style="color: rgb(0,0,255)">$froms</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(204,102,204)">0</span><span style="color: rgb(102,204,102)">]</span>, <span style="color: rgb(0,0,255)">$fromarr</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$from</span> = <span style="color: rgb(0,0,255)">$fromarr</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(204,102,204)">0</span><span style="color: rgb(102,204,102)">]</span>; <span style="color: rgb(102,204,102)">}</span> <span style="font-style: italic; color: rgb(128,128,128)">// Open an SMTP connection</span> <span style="color: rgb(0,0,255)">$cp</span> = <a href="http://www.php.net/fsockopen" target="_blank"><span style="color: rgb(0,0,102)">fsockopen</span></a> <span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$GLOBAL</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(255,0,0)">"SMTP_SERVER"</span><span style="color: rgb(102,204,102)">]</span>, <span style="color: rgb(0,0,255)">$GLOBAL</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(255,0,0)">"SMTP_PORT"</span><span style="color: rgb(102,204,102)">]</span>, &<span style="color: rgb(0,0,255)">$errno</span>, &<span style="color: rgb(0,0,255)">$errstr</span>, <span style="color: rgb(204,102,204)">1</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span> <span style="color: rgb(102,204,102)">(</span>!<span style="color: rgb(0,0,255)">$cp</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to even make a connection"</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"220"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to connect"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Say hello...</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"HELO "</span>.<span style="color: rgb(0,0,255)">$GLOBAL</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(255,0,0)">"SMTP_SERVER"</span><span style="color: rgb(102,204,102)">]</span>.<span style="color: rgb(255,0,0)">"<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"250"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to Introduce"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// perform authentication</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"auth login<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"334"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to Initiate Authentication"</span>; <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <a href="http://www.php.net/base64_encode" target="_blank"><span style="color: rgb(0,0,102)">base64_encode</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$GLOBAL</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(255,0,0)">"SMTP_USERNAME"</span><span style="color: rgb(102,204,102)">]</span><span style="color: rgb(102,204,102)">)</span>.<span style="color: rgb(255,0,0)">"<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"334"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to Provide Username for Authentication"</span>; <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <a href="http://www.php.net/base64_encode" target="_blank"><span style="color: rgb(0,0,102)">base64_encode</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$GLOBAL</span><span style="color: rgb(102,204,102)">[</span><span style="color: rgb(255,0,0)">"SMTP_PASSWORD"</span><span style="color: rgb(102,204,102)">]</span><span style="color: rgb(102,204,102)">)</span>.<span style="color: rgb(255,0,0)">"<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"235"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Failed to Authenticate"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Mail from...</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"MAIL FROM: <$from><span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"250"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"MAIL FROM failed"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Rcpt to...</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"RCPT TO: <$to><span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"250"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"RCPT TO failed"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Data...</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"DATA<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"354"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"DATA failed"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Send To:, From:, Subject:, other headers, blank line, message, and finish</span> <span style="font-style: italic; color: rgb(128,128,128)">// with a period on its own line (for end of message)</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>, <span style="color: rgb(255,0,0)">"To: $to<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>From: $from<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>Subject: $subject<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>$headers<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span><span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>$message<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>.<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"250"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"Message Body Failed"</span>; <span style="font-style: italic; color: rgb(128,128,128)">// ...And time to quit...</span> <a href="http://www.php.net/fputs" target="_blank"><span style="color: rgb(0,0,102)">fputs</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(255,0,0)">"QUIT<span style="color: rgb(0,0,153); font-weight: bold">\r</span><span style="color: rgb(0,0,153); font-weight: bold">\n</span>"</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,255)">$res</span>=<a href="http://www.php.net/fgets" target="_blank"><span style="color: rgb(0,0,102)">fgets</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$cp</span>,<span style="color: rgb(204,102,204)">256</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><a href="http://www.php.net/substr" target="_blank"><span style="color: rgb(0,0,102)">substr</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$res</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span> != <span style="color: rgb(255,0,0)">"221"</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(255,0,0)">"QUIT failed"</span>; <span style="color: rgb(177,177,0)">return</span> <span style="color: rgb(0,0,0); font-weight: bold">true</span>; <span style="color: rgb(102,204,102)">}</span> </div>
试试其它关键字
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3