通行证: 用户 密码 域名空间  下载中心 社区论坛 信息公告 my小屋
联系我们
设为首页
加入收藏

 

qq,asp,php,jsp,xml,sql,.net,编程 程序 网页图象 建站经验 私服
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿
论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图
专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版
社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 韩国素材 | 素材图库 | 广告服务 | 服务
当前位置:首页>>在线服务>>疑难解答>>正文 新版上线![旧版]
注:打开慢时请稍等

发mail的php代码

http://www.iyit.net  日期:2006-10-6 15:33:44  来源:iyit.net收集  点击:
参加讨论
请大家帮帮忙,谁有发mail的php代码?谢谢!  
---------------------------------------------------------------  
 
这里有很多email相关的class.  
 
http://www.phpe.net/?n=classes&t=12  
 
 
---------------------------------------------------------------  
 
一个非常不错的发邮件的类,(在网上找的),跟大家共享,代码太长,分成三个部份了.  
<?php  
 
##########服务器参数设置################  
$smtpserver  =  "";//smtp服务器  
$smtpserverport  =25;//smtp服务器端口  
$smtpusermail  =  "";//smtp服务器的用户邮箱  
$smtpuser  =  "";//smtp服务器的用户帐号  
$smtppass  =  "";//smtp服务器的用户密码  
$mailtype  =  "txt";//邮件格式(html/txt),txt为文本邮件  
$mailsubject  =  "just  a  test";//邮件主题  
$mailbody        =  "hello"              //邮件内容  
##########################################  
 
 
$smtp  =  new  smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.  
$smtp->debug  =  true;//是否显示发送的调试信息  
$smtp->sendmail($smtpemailto,  $smtpusermail,  $mailsubject,  $mailbody,  $mailtype)  
---------------------------------------------------------------  
 
class  smtp  
{  
               /*  public  variables  */  
               var  $smtp_port;  
               var  $time_out;  
               var  $host_name;  
               var  $log_file;  
               var  $relay_host;  
               var  $debug;  
               var  $auth;  
               var  $user;  
               var  $pass;  
 
               /*  private  variables  */  
               var  $sock;  
 
               /*  constractor  */  
               function  smtp($relay_host  =  "",  $smtp_port  =  25,$auth  =  false,$user,$pass)  
               {  
                               $this->debug            =  false;  
                               $this->smtp_port    =  $smtp_port;  
                               $this->relay_host  =  $relay_host;  
                               $this->time_out      =  30;  //is  used  in  fsockopen()  
                               #  
                               $this->auth  =  $auth;//auth  
                               $this->user  =  $user;  
                               $this->pass  =  $pass;  
                               #  
                               $this->host_name    =  "localhost";  //is  used  in  helo  command  
                               $this->log_file      =  "";  
 
                               $this->sock              =  false;  
               }  
 
               /*  main  function  */  
               function  sendmail($to,  $from,  $subject  =  "",  $body  =  "",  $mailtype,  $cc  =  "",  $bcc  =  "",  $additional_headers  =  "")  
               {  
                               $mail_from  =  $this->get_address($this->strip_comment($from));  
                               $body  =  ereg_replace("(^  &brvbar(\r\n))(\\.)",  "\\1.\\3",  $body);  
                               $header  .=  "mime-version:1.0\r\n";  
                                                               if($mailtype=="html"){  
                               $header  .=  "content-type:text/html\r\n";  
                                                               }  
                               $header  .=  "to:  ".$to."\r\n";  
                               if  ($cc  !=  "")  {  
                                               $header  .=  "cc:  ".$cc."\r\n";  
                               }  
                               $header  .=  "from:  $from<".$from.">\r\n";  
                               $header  .=  "subject:  ".$subject."\r\n";  
                               $header  .=  $additional_headers;  
                               $header  .=  "date:  ".date("r")."\r\n";  
                               $header  .=  "x-mailer:by  redhat  (php/".phpversion().")\r\n";  
                               list($msec,  $sec)  =  explode("  ",  microtime());  
                               $header  .=  "message-id:  <".date("ymdhis",  $sec).".".($msec*1000000).".".$mail_from.">\r\n";  
                               $to  =  explode(",",  $this->strip_comment($to));  
 
                               if  ($cc  !=  "")  {  
                                               $to  =  array_merge($to,  explode(",",  $this->strip_comment($cc)));  
                               }  
 
                               if  ($bcc  !=  "")  {  
                                               $to  =  array_merge($to,  explode(",",  $this->strip_comment($bcc)));  
                               }  
 
                               $sent  =  true;  
                               foreach  ($to  as  $rcpt_to)  {  
                                               $rcpt_to  =  $this->get_address($rcpt_to);  
                                               if  (!$this->smtp_sockopen($rcpt_to))  {  
                                                               $this->log_write("error:  cannot  send  email  to  ".$rcpt_to."\n");  
                                                               $sent  =  false;  
                                                               continue;  
                                               }  
                                               if  ($this->smtp_send($this->host_name,  $mail_from,  $rcpt_to,  $header,  $body))  {  
                                                               $this->log_write("e-mail  has  been  sent  to  <".$rcpt_to.">\n");  
                                               }  else  {  
                                                               $this->log_write("error:  cannot  send  email  to  <".$rcpt_to.">\n");  
                                                               $sent  =  false;  
                                               }  
                                               fclose($this->sock);  
                                               $this->log_write("disconnected  from  remote  host\n");  
                               }  
                               return  $sent;  
               }  
 
               /*  private  functions  */  
 
               function  smtp_send($helo,  $from,  $to,  $header,  $body  =  "")  
               {  
                               if  (!$this->smtp_putcmd("helo",  $helo))  {  
                                               return  $this->smtp_error("sending  helo  command");  
                               }  
       #auth  
       if($this->auth){  
                               if  (!$this->smtp_putcmd("auth  login",  base64_encode($this->user)))  {  
                                               return  $this->smtp_error("sending  helo  command");  
                               }  
 
                               if  (!$this->smtp_putcmd("",  base64_encode($this->pass)))  {  
                                               return  $this->smtp_error("sending  helo  command");  
                               }  
               }  
       #  
                               if  (!$this->smtp_putcmd("mail",  "from:<".$from.">"))  {  
                                               return  $this->smtp_error("sending  mail  from  command");  
                               }  
 
                               if  (!$this->smtp_putcmd("rcpt",  "to:<".$to.">"))  {  
                                               return  $this->smtp_error("sending  rcpt  to  command");  
                               }  
 
                               if  (!$this->smtp_putcmd("data"))  {  
                                               return  $this->smtp_error("sending  data  command");  
                               }  
 
                               if  (!$this->smtp_message($header,  $body))  {  
                                               return  $this->smtp_error("sending  message");  
                               }  
 
                               if  (!$this->smtp_eom())  {  
                                               return  $this->smtp_error("sending  <cr><lf>.<cr><lf>  [eom]");  
                               }  
 
                               if  (!$this->smtp_putcmd("quit"))  {  
                                               return  $this->smtp_error("sending  quit  command");  
                               }  
 
                               return  true;  
               }  
 
               function  smtp_sockopen($address)  
               {  
                               if  ($this->relay_host  ==  "")  {  
                                               return  $this->smtp_sockopen_mx($address);  
                               }  else  {  
                                               return  $this->smtp_sockopen_relay();  
                               }  
               }  
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;;  
               }  
---------------------------------------------------------------  
 
function  smtp_sockopen_mx($address)  
               {  
                               $domain  =  ereg_replace("^.+@([^@]+)$",  "\\1",  $address);  
                               if  (!@getmxrr($domain,  $mxhosts))  {  
                                               $this->log_write("error:  cannot  resolve  mx  \"".$domain."\"\n");  
                                               return  false;  
                               }  
                               foreach  ($mxhosts  as  $host)  {  
                                               $this->log_write("trying  to  ".$host.":".$this->smtp_port."\n");  
                                               $this->sock  =  @fsockopen($host,  $this->smtp_port,  $errno,  $errstr,  $this->time_out);  
                                               if  (!($this->sock  &&  $this->smtp_ok()))  {  
                                                               $this->log_write("warning:  cannot  connect  to  mx  host  ".$host."\n");  
 
---------

编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:请教,如何用gd生成透明背景图片?50分相送
下一篇:把网页压缩输出?
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

 相关文章
我在windows  xp上安装apache2.044+php apache+php,怎样打开session支持?? 在linux中怎么配置pdflib和php  高分!
怎么样同时解释.php和.php3的文件呀,急 php 4.1.0 及以后版本使用post变量的接 apache2-win32+php的成功安装方法
我只是想在本地机上学习php ,还要安装 装了php。运行时出现在以下提示 php在win2003上面怎样安装?
php 在linux 下如何開啟ftp功能 如何屏蔽掉 phpinfo() php.ini中文版
请问怎样降低php的警告等级? 一个打击了我学习php热情的问题:怎么样 php初学者的入门问题
运行php程序会出现乱码是怎么回事?zen 如何让php拥有root的权限? 为什么php中的函数mail()不能发送邮件
成功地在linux/unix下安装apache+php+o 在win2k下如何安装apache、mysql、php? 请问高手:iis5.0+php4.0安装问题
php session变量在下一页不能读取值的问 php安装、配置手册(新手入门必读、高手 php_gd_gif.dll那里有的下载,还有什么办
最新更新 热点排行 推荐新闻
我在windows  xp上安装apache2.044+ph
apache+php,怎样打开session支持??
在linux中怎么配置pdflib和php  高分!
怎么样同时解释.php和.php3的文件呀,
php 4.1.0 及以后版本使用post变量的接
我在windows  xp上安装apache2.044+ph
apache+php,怎样打开session支持??
在linux中怎么配置pdflib和php  高分!
怎么样同时解释.php和.php3的文件呀,
php 4.1.0 及以后版本使用post变量的接
apache2-win32+php的成功安装方法
我只是想在本地机上学习php ,还要安装
装了php。运行时出现在以下提示
如何安装apache2.0
怎么删除mysql???
我在windows  xp上安装apache2.044+ph
apache+php,怎样打开session支持??
如何实现注册时的确认码功能
请帮忙解决,图随机上传,不限量,定位
有没有很好方法,获得在线登陆用户名单
qq密码被盗怎么办!我教你找回密码
如何控制我的电脑只允许登录我自己的q
qq2006 beta3隆重发布 实用功能一一奉
美国微软总部相中重庆15岁网络奇才(图
百度声明称遭受有史以来最大规模黑客攻
被删除系统文件恢复全攻略
使用身份验证来禁止内部用户上网 
国内首次发现带有感染文件特征盗号病毒
06年08月31日石家庄太和 内存报价
用css控制透明图片 
exeplorer.exe错误的问题的总结、解决
三分钟让你的系统变处女:acronis tru
让你的密码成为黑客的“耻辱”
比较sql server2005和oracle 10g r2
比较sql server2005和oracle 10g r2
sql server2005的xml数据类型之基础篇
sql server服务器的“偷梁换柱”
在win2003下mysql数据库每天自动备份
win2000 apache php mysql 安装及安全
mysql账户相关
快速安装windows操作系统独家秘籍
 友情链接
设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
copyrights © 2004-2006 iyit.net all rights reserved.
网站合作、广告联系qq:147007642、466949678
易特网络技术 点击这里给我发消息