php imap收邮件类代码(1/11)
-- php教程myadmin sql dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- host: localhost
-- generation time: jun 29, 2010 at 09:27 am
-- server version: 5.0.51
-- php version: 5.2.6
set sql_mode="no_auto_value_on_zero";
/*!40101 set @old_character_set_client=@@character_set_client */;
/*!40101 set @old_character_set_results=@@character_set_results */;
/*!40101 set @old_collation_connection=@@collation_connection */;
/*!40101 set names utf8 */;
--
-- database: `test`
--
-- --------------------------------------------------------
--
-- table structure for table `maillist`
--
create table if not exists `maillist` (
`id` int(11) not null auto_increment,
`title` text collate utf8_unicode_ci not null,
`content` mediumtext collate utf8_unicode_ci not null,
`senduser` varchar(50) collate utf8_unicode_ci not null,
`sendmail` varchar(200) collate utf8_unicode_ci not null,
`sendtime` int(11) not null,
`accept_email` varchar(200) collate utf8_unicode_ci not null,
`cc_email` varchar(200) collate utf8_unicode_ci not null,
`bcc_email` varchar(200) collate utf8_unicode_ci not null,
`msessage_id` varchar(200) collate utf8_unicode_ci not null,
`msgno` int(11) not null comment '邮件的序号,为0表示已经下载结束',
`is_download` tinyint(4) not null default '0',
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `maillist`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_account`
--
create table if not exists `mail_account` (
`id` int(11) not null auto_increment,
`username` varchar(100) not null,
`password` varchar(50) not null,
`emailaddress` varchar(100) not null,
`mailserver` varchar(50) not null,
`servertype` varchar(10) not null,
`port` varchar(10) not null,
primary key (`id`)
) engine=myisam default charset=latin1 auto_increment=1 ;
--
-- dumping data for table `mail_account`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_attach`
--
create table if not exists `mail_attach` (
`id` int(11) not null auto_increment,
`mail_id` int(11) not null,
`filename` varchar(200) collate utf8_unicode_ci not null,
`filename_tmp` varchar(200) collate utf8_unicode_ci not null,
`download_time` datetime not null,
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `mail_attach`
--
邮件群发其实非常的简单只要利用遍历发布就可以了,下面本例子利用了phpmailer函数来登录163邮箱给QQ邮箱发邮件,希望本文章对各位同学有帮助。
*@author ray
*@since 2009-08-07
smtp邮件帐号一定要多,不然会被qq服务器当作垃圾邮件。
2.得适当的休眠
smtp.dat文件格式为
smtp.163.com|sss@163.com|密码
smtp.sina.com|www@sina.com|密码 www.111cn.net
程序随机抽取一个连接,发送邮件,如果发送不成功,将该邮件地址存入sleepmail.dat休眠30分后在发送(这个是为了连接smtp服务器多次后发送不成功而做的修改)。
*/
代码如下 | 复制代码 |
define('__debug__', false); define('__ps教程w_file__', dirname(__file__) . '/smtp.dat'); define('sleeping_email', dirname(__file__) . "/sleepmail.dat");//休眠的email define('sleeping_time', 1800);//休眠多长时间,以秒为单位 define('file_append', 1); if (!function_exists('file_put_contents')) { function file_put_contents($n, $d, $flag = false) { $mode = ($flag == file_append || strtoupper($flag) == 'file_append') ? 'a' : 'w'; $f = @fopen($n, $mode); if ($f === false) { return 0; } else { if (is_array($d)) $d = implode($d); $byteswritten = fwrite($f, $d); fclose($f); return $byteswritten; } } } $errorno = 0; $errormsg = ''; $currtime = time(); $unusemails = array(); //收件人和邮件标题和邮件内容 $to = isset($argv[1]) ? $argv[1] : "" ; $subject = isset($argv[2]) ? $argv[2] : ""; $mailfile = isset($argv[3]) ? $argv[3] : "" ; if (__debug__) { echo " file:$mailfile to:$to subject:$subject "; } if (empty($mailfile) || empty($to) || empty($subject)) { $errorno = 1; $errormsg = "参数不全"; } //加载不可用的email列表 if (!$errorno) { if (file_exists(sleeping_email)) { $sleepmails = file(sleeping_email); if (!empty($sleepmails)) { foreach($sleepmails as $sleepmail) { //解析 if (false !== strpos($sleepmail, '|')) { $tmp = explode('|', $sleepmail); if (isset($tmp[0]) && isset($tmp[1])) { $mail = trim($tmp[0]); $time = trim($tmp[1]); //是否可用 if ( ($currtime - $time )< sleeping_time) { $unusemails[] = $mail; } } } } } } } if (!$errorno) { //随机加载smtp服务器和smtp用户名和密码 $info = file(__psw_file__); $len = count($info); do { $rnd = mt_rand(0, $len - 1); $line = isset($info[$rnd]) ? $info[$rnd] : ""; if (false !== strpos($line, '|')) { $tmp = explode('|', $line); if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) { $smtpserver = trim($tmp[0]); $frommail = trim($tmp[1]); $psw = trim($tmp[2]); $smtpusername = substr($frommail, 0, strrpos($frommail, '@')); } } }while (in_array($frommail, $unusemails));//如果在不可用的列表中,在次加载 if (!isset($smtpserver) || !isset($frommail) || !isset($psw)) { $errorno = 2; $errormsg = "没找到发件人qq信箱和密码"; } } if (!$errorno && __debug__) { echo "smtp:$smtpserver from:$frommail psw:$psw user:$smtpusername "; } if (!$errorno) { //通过phpmailer连接smtp服务器发信 require(dirname(__file__) . "/phpmailer/class.phpmailer.php"); require(dirname(__file__) . "/phpmailer/class.smtp.php"); $mail = new phpmailer(); $body = $mail->getfile($mailfile); $body = eregi_replace("[]",'',$body); //charset $mail->charset = "gb2312"; //$mail->smtpdebug = 2;//www.111cn.net用于显示具体的smtp错误 $mail->issmtp(); $mail->smtpauth = true; if ("smtp.qq.com" == trim($smtpserver)) { $mail->username = $frommail; } else { $mail->username = $smtpusername; } $mail->password = $psw; $mail->host = $smtpserver; $mail->from = $frommail; $mail->fromname = "晴天网络"; $mail->ishtml(true); $mail->addaddress($to); $mail->subject = $subject; $mail->body = $body; if (!$mail->send()) { // echo "message could not be sent. "; $errorno = 3; $errormsg = $mail->errorinfo; } else { echo " send to $to success use $frommail "; exit; } } if (3 == $errorno) { //记录信息,该信息地址休眠n分钟 $content = "$frommail|" . time() . " ";//email|当前时间戳 file_put_contents(sleeping_email, $content, file_append); } echo " error no($errorno) " . $errormsg . " "; exit; |
代码如下 | 复制代码 |
<html> |
php代码
代码如下 | 复制代码 |
<?php |
代码如下 | 复制代码 |
<?php <?php |
在apache 下建立高可扩展的web邮件系统实例
1.2 要求
该文档提到了三种服务器:web服务器,imap服务器和LDAP服务器。这些服务器可以位于独立的主机上,或若干个独立的机 器上(例如:23个web服务器,5个LDAP服务器和10个IMAP服务器),或单台服务器上。同时需要具有在 Linux环境下从源代码安装软件的基本知识
1.3 使用的软件
构建该系统需要以下的软件包: Apache 1.3.6 或以上版本 http://www.apache.org/ PHP 3.0.12 需要将对IMAP和LDAP的支持编译进来 OpenLDAP 1.2 Cyrus 1.5.19 (注:不要使用1.6) postfix 19990627 pwcheck_ldap patch (针对cyrus 1.5的) IMP (2.0.4, 2.0.10, 和2.1.3-dev进行了测试) UW IMAP (针对 c-client) 注:cyrus 1.6树使用了一种不同的,被称作SASL的鉴别方法, pwcheck_ldap补丁不是针对这种鉴别方法设计的。然而,对SASL的LDAP的补丁正在设计中,你可以参观该主页来获得最新信息。
1.4 特别注释
该系统有一个部分的可伸缩性不是很好:IMP使用的用来保存会话数据,参 数,及地址簿的SQL服务器。
2. 安装软件 2.1 Web服务器的安装
在web服务器上,管理员需要安装下列软件包:Apache, PHP, postfix, OpenLDAP, UW IMAP, 及IMP. 安装Apache和PHP是很容易的,具体步骤在PHP软件包中的安装导引有详细的说 明。在安装PHP时,你需要将对LDAP和IMAP的支持编译进来。 安装postfix可以参考随软件包的安装指南,特别要注意文件LDAP_README。
2.2 LDAP服务器的安装
需要安装OpenLDAP软件 来构建LDAP服务器。你需要决定一个root dn并相应地向LDAP的db中加入设置。
2.3 IMAP服务器的安装
在IMAP服务器上,你将需要安装LDAP, postfix, Cyrus及cyrus的pwcheck_ldap补丁。编译postfix时需要有加入对ldap的支持。根据软件安装文档安装Cyrus,但 是需要根据pwcheck_ldap补丁的文档对pwcheck_ldap.c进行修改。另外需要修改pwcheck_ldap.c来提供ldap服 务器及根dn信息;同样若在linux服务器上运行IMAP服务器,则需要在在文件pwcheck_ldap.c作如下修正: 增加行: #include <linux/stddef.h> 另外还需要做一些别的语法修改,具体可以在编译 是发现。 使用下面的命令配置cyrus:
./configure --with-login=unix_pwcheck --with-pwcheck=ldap
后面的编译及安装则根据cyrus的文档;
3. 如何配置服务器协同工作 3.1 LDAP服务器 的配置
每个在LDAP数据库教程中的 邮件用户信息除了其他的希望提供的信息以外需要有下面的内容:(假设你的根dn是o=someorg, c=US):
dn: uid=someuser, o=someorg, c=us
uid: someuser
userpassword: somepassword
maildrop: fulladdress@machine.dom.ain
mailacceptinggeneralid: someuser
mailacceptinggeneralid: somealias
同样,需要选择一个用户拥有cyrus管理权限。只有需要在imap服务器上配置cyrus时,才会需要考虑管理问题。另外,最好不要给一个已经 存在的用户添加管理权限,这样做可能导致安全问题或者导致该用户不能查看自己的信件的问题。
3.2 imap服务器的配置
配置在IMAP服务器上的postfix使用ldap来进行别名匹配。在文档LDAP_README对这个问题进行 了说明。对于Cyrus,按照软件包的安装说明文件进行即可。同样,不要忘记 激活pwcheck并在imap.conf中增添管理用户。
3.3 web服务器
在这一步的设置中,web服务器同样是作为接收邮件网关的前端。配 置postfix来使用ldap进行别名匹配。从而实现检查LDAP的maildrop表项并转发该邮件到maildrop地址,所以在maildrop 中需要全邮件名。 例如,你可以将700,000个用户分配到各个服务器上,平均每台服务器10000个用户。邮件目的地 址是user1@dom.ain的邮件将接入到某台WEB服务器,而该邮件将根据maildrop属性被转发到地址,而发网 user657的邮件将被转发给user657@mail34。而且,maildrop属性同时可以被用作转发地址,如给user302的信 件被转发给someuser@somewhereelse.com">
例如,你可以将700,000个用户分配到各个服务器上,平均每台服务 器10000个用户。邮件目的地址是user1@dom.ain的邮件将接入到某台WEB服务器,而该邮件将根据maildrop属性 被转发到地址,而发网user657的邮件将被转发给user657@mail34。而且,maildrop属性同时可以被用作转发地 址,如给user302的信件被转发给someuser@somewhereelse.com。
对IMP的培配置一般将根据软件文档,配置结束以后,需要做如下修 改: 在config/defaults.php教程3增添如下内容:
/* LDAP/IMAP Server Default */ $default->LDAP_server = 'ldap.dom.ain'; $default->LDAP_dn = 'o=someorg,c=US'; $default->LDAP_search_field = 'uid'; $default->ldap_choose_server = true;
to mailbox.php3 apply the following patch:Index: mailbox.php3 =================================================================== RCS file: /home/cvs/imp/mailbox.php3,v retrieving revision 2.29 diff -c -r2.29 mailbox.php3 *** mailbox.php3 1999/07/29 07:20:00 2.29 --- mailbox.php3 1999/08/04 18:04:10 *************** *** 29,34 **** --- 29,51 ---- require './lib/mimetypes.lib'; require './config/defaults.php3'; + /************LDAP**************/ + + if ($default->ldap_choose_server) { + $ldapconnect = ldap_connect($default->LDAP_server); + if ($ldapconnect) { + print("YES! "); + $ldapbind = ldap_bind($ldapconnect); + $ldaps教程earch = ldap_search($ldapconnect, $default->LDAP_dn, $default->LDAP_search_field."=".$imapuser, array("maildrop")); + $ldapget = ldap_get_entries($ldapconnect, $ldapsearch); + $ldapspl = explode("@", $ldapget[0]["maildrop"][0]); + $server = $ldapspl[1]; + $port = $default->port; + } + }
+ /**********end ldap************/ + + /* Html styles configuration */ require './config/html.php3'; /* Mailbox configuration */ 全部配置结束以后,将具有一个高可扩展性的web邮件系统。
注:1999年8月,IMP的新版本已经包含了这些补丁的内容,所以如果使 用新版本的话,就不需添加这些内容。
4. Miscellaneous 4.1 Adding Users
这里是一小段向LDAP服务器中增添用户的代码,并且同时向cyrus增添一个邮件用户。这是针对 IMAP服务器设计的,但是你可以修改其适应别的环境。
<?php
$ldapconn = ldap_connect("ldap.dom.ain");
$machine = "mail01";
if ($ldapconn)
{
$ldhb = ldap_bind($ldapconn, "cn=cyrusadmin, o=someorg,c=US","password");
$dn = "uid=". $username .", o=someorg, c=US";
$info["uid"]=$username;
$info["userpassword"] = $password;
$info["objectclass"] = "account";
$info["maildrop"] = $username ."@" .$machine .".dom.ain";
$info["mailacceptinggeneralid"] = $username;
$ldhb = ldap_add($ldapconn, $dn, $info);
ldap_close($ldapconn);
}
$imapconn = imap_open("{" .$machine .".dom.ain:143}", "cyrusadmin","password");
if ($imapopen)
{
imap_createmailbox($imapconn, "{" .$machine ."dom.ain:143}user.".$username );
imap_close($imapconn);
}
?>
注:由于一个bug的问题,这里使用明文password。
相关文章
- 以前我们开发大型项目时都会用到svn来同步,因为开发产品的人过多,所以我们会利用软件来管理,今天发有一居然可以利用php来管理svn哦,好了看看吧。 代码如下 ...2016-11-25
- 操作类就是把一些常用的一系列的数据库或相关操作写在一个类中,这样调用时我们只要调用类文件,如果要执行相关操作就直接调用类文件中的方法函数就可以实现了,下面整理了...2016-11-25
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
- 本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
- 其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
- 无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的文章。1.实现原理 几种常见的实现方法,各有利弊。其中...2015-10-23
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 在一些复杂的系统中,要求对信息栏目进行无限级的分类,以增强系统的灵活性。那么PHP是如何实现无限级分类的呢?我们在本文中使用递归算法并结合mysql数据表实现无限级分类。 递归,简单的说就是一段程序代码的重复调用,当把...2015-10-23
- 小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
php导出csv格式数据并将数字转换成文本的思路以及代码分享
php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07