仓酷云

标题: PHP网页设计POP3、SMTP邮件收发法式 [打印本页]

作者: 萌萌妈妈    时间: 2015-2-4 00:29
标题: PHP网页设计POP3、SMTP邮件收发法式
我先解释一下我的学习思路。smtp|法式   <?php
if ($EMAIL_INC) return;
$EMAIL_INC= "defined";
define( "SmtpPort",25);

class Pop3 {
var $subject; // 邮件主题
var $from_email; // 发件人地址
var $from_name; // 发件人姓名
var $to_email; // 收件人地址
var $to_name; // 收件人姓名
var $body; // 邮件内容
var $filename; // 文件名
var $socket; // 以后的 socket
var $Line;
var $Status;

function pop3_open($server, $port)
{

$this->Socket = fsockopen($server, $port);
if ($this->Socket <= 0){
return false;
}
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return false;
return true;
}

function pop3_user($user)
{

if ($this->Socket < 0){
return false;
}
fputs($this->Socket, "USER $this->userrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return false;

return true;
}

function pop3_pass( $pass)
{

fputs($this->Socket, "PASS $passrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

return 1;
}

function pop3_stat()
{

fputs($this->Socket, "STATrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

if (!eregi( "+OK (.*) (.*)", $this->Line, $regs))
return 0;

return $regs[1];
}

function pop3_list()
{
fputs($this->Socket, "LISTrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

$i = 0;
while (substr($this->Line = fgets($this->Socket, 1024), 0, 1) <> ".")
{
$articles[$i] = $this->Line;
$i++;
}
$articles[ "count"] = $i;

return $articles;
}

function pop3_retr($nr)
{

fputs($this->Socket, "RETR $nrrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

while (substr($this->Line = fgets($this->Socket, 1024), 0, 1) <> ".")
{
$data[$i] = $this->Line;
$i++;
}
$data[ "count"] = $i;

return $data;
}

function pop3_dele( $nr)
{

fputs($this->Socket, "DELE $nrrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;
return 1;
}

function pop3_quit()
{

fputs($this->Socket, "QUITrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

return 1;
}
}

class Smtp {

var $Subject; // string the email's subject
var $FromName; // string sender's name (opt)
var $ToName; // string recipient's name (opt)
var $Body; // string body copy
var $Attachment; // attachment (optional)
var $AttachmentType;
var $Socket;
var $Line;
var $Status;

function Smtp($Server = "localhost",$Port = SmtpPort)
{
return $this->Open($Server, $Port);
}

function SmtpMail($FromEmail, $FromName, $ToEmail, $ToName, $Subject, $Body, $Attachment=null, $AttachmentType= "TEXT")
{
$this->Subject = $Subject;
$this->ToName = $ToName;

$this->FromName = $FromName;
$this->Body = $Body;

$this->Attachment = $Attachment;
$this->AttachmentType = $AttachmentType;

if ($this->Helo() == false){
return false;
}
if ($this->MailFrom($FromEmail) == false){
return false;
}
if ($this->RcptTo($ToEmail) == false){
return false;
}
if ($this->Body() == false){
return false;
}
if ($this->Quit() == false){
return false;
}
}

function Open($Server, $Port)
{

$this->Socket = fsockopen($Server, $Port);
if ($this->Socket < 0) return false;

$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}


function Helo()
{
if (fputs($this->Socket, "helorn") < 0 ){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}

function Ehlo()
{

/* Well, let's use "helo" for now.. Until we need the
extra func's [Unk]
*/
if(fputs($this->Socket, "helo localhostrn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}


function MailFrom($FromEmail)
{

if (fputs($this->Socket, "MAIL FROM: <$FromEmail>rn")<0){
return false;
}

$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}

function RcptTo($ToEmail)
{

if(fputs($this->Socket, "RCPT TO: <$ToEmail>rn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;
return true;
}

function Body()
{
$FileSize = 0;
$Attachment = null;
$fp = null;

$buffer = sprintf( "From: %srnTo:%srnSubject:%srn", $this->FromName, $this->ToName, $this->Subject);

if(fputs($this->Socket, "DATArn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "3") return false;

if(fputs($this->Socket, $buffer)<0){
return false;
}


if ($this->Attachment == null){

if(fputs($this->Socket, "MIME-Version: 1.0rnContent-Type: text/plain; charset=ISO-8859-1rnContent-Transfer-Encoding: 7bitrnrn")<0){
return false;
}
if(fputs($this->Socket, "$this->Bodyrnrn")<0){
return false;
}

if(fputs($this->Socket, ".rn")<0){
return false;
}

$this->
POP3、SMTP邮件收发法式

 宣布工夫: 2001年09月28日 浏览次数: 18 保举给伴侣 打印本页

<?php
if ($EMAIL_INC) return;
$EMAIL_INC= "defined";
define( "SmtpPort",25);

class Pop3 {
var $subject; // 邮件主题
var $from_email; // 发件人地址
var $from_name; // 发件人姓名
var $to_email; // 收件人地址
var $to_name; // 收件人姓名
var $body; // 邮件内容
var $filename; // 文件名
var $socket; // 以后的 socket
var $Line;
var $Status;

function pop3_open($server, $port)
{

$this->Socket = fsockopen($server, $port);
if ($this->Socket <= 0){
return false;
}
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return false;
return true;
}

function pop3_user($user)
{

if ($this->Socket < 0){
return false;
}
fputs($this->Socket, "USER $this->userrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return false;

return true;
}

function pop3_pass( $pass)
{

fputs($this->Socket, "PASS $passrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

return 1;
}

function pop3_stat()
{

fputs($this->Socket, "STATrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

if (!eregi( "+OK (.*) (.*)", $this->Line, $regs))
return 0;

return $regs[1];
}

function pop3_list()
{
fputs($this->Socket, "LISTrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

$i = 0;
while (substr($this->Line = fgets($this->Socket, 1024), 0, 1) <> ".")
{
$articles[$i] = $this->Line;
$i++;
}
$articles[ "count"] = $i;

return $articles;
}

function pop3_retr($nr)
{

fputs($this->Socket, "RETR $nrrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

while (substr($this->Line = fgets($this->Socket, 1024), 0, 1) <> ".")
{
$data[$i] = $this->Line;
$i++;
}
$data[ "count"] = $i;

return $data;
}

function pop3_dele( $nr)
{

fputs($this->Socket, "DELE $nrrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;
return 1;
}

function pop3_quit()
{

fputs($this->Socket, "QUITrn");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "+") return 0;

return 1;
}
}

class Smtp {

var $Subject; // string the email's subject
var $FromName; // string sender's name (opt)
var $ToName; // string recipient's name (opt)
var $Body; // string body copy
var $Attachment; // attachment (optional)
var $AttachmentType;
var $Socket;
var $Line;
var $Status;

function Smtp($Server = "localhost",$Port = SmtpPort)
{
return $this->Open($Server, $Port);
}

function SmtpMail($FromEmail, $FromName, $ToEmail, $ToName, $Subject, $Body, $Attachment=null, $AttachmentType= "TEXT")
{
$this->Subject = $Subject;
$this->ToName = $ToName;

$this->FromName = $FromName;
$this->Body = $Body;

$this->Attachment = $Attachment;
$this->AttachmentType = $AttachmentType;

if ($this->Helo() == false){
return false;
}
if ($this->MailFrom($FromEmail) == false){
return false;
}
if ($this->RcptTo($ToEmail) == false){
return false;
}
if ($this->Body() == false){
return false;
}
if ($this->Quit() == false){
return false;
}
}

function Open($Server, $Port)
{

$this->Socket = fsockopen($Server, $Port);
if ($this->Socket < 0) return false;

$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}


function Helo()
{
if (fputs($this->Socket, "helorn") < 0 ){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}

function Ehlo()
{

/* Well, let's use "helo" for now.. Until we need the
extra func's [Unk]
*/
if(fputs($this->Socket, "helo localhostrn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}


function MailFrom($FromEmail)
{

if (fputs($this->Socket, "MAIL FROM: <$FromEmail>rn")<0){
return false;
}

$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;

return true;
}

function RcptTo($ToEmail)
{

if(fputs($this->Socket, "RCPT TO: <$ToEmail>rn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "2") return false;
return true;
}

function Body()
{
$FileSize = 0;
$Attachment = null;
$fp = null;

$buffer = sprintf( "From: %srnTo:%srnSubject:%srn", $this->FromName, $this->ToName, $this->Subject);

if(fputs($this->Socket, "DATArn")<0){
return false;
}
$this->Line = fgets($this->Socket, 1024);

$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);

if ($this->Status[ "LASTRESULT"] <> "3") return false;

if(fputs($this->Socket, $buffer)<0){
return false;
}


if ($this->Attachment == null){

if(fputs($this->Socket, "MIME-Version: 1.0rnContent-Type: text/plain; charset=ISO-8859-1rnContent-Transfer-Encoding: 7bitrnrn")<0){
return false;
}
if(fputs($this->Socket, "$this->Bodyrnrn")<0){
return false;
}

if(fputs($this->Socket, ".rn")<0){
return false;
}

$this->
  如果不会怎么办,我的视频教程里有个最简单的留言板 最开始离不开模仿,
作者: 若天明    时间: 2015-2-4 13:13
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 再现理想    时间: 2015-2-5 13:43
建数据库表的时候,int型要输入长度的,其实是个摆设的输入几位都没影响的,只要大于4就行,囧。
作者: 再见西城    时间: 2015-2-7 23:55
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
作者: 小妖女    时间: 2015-2-23 17:14
本人接触php时间不长,算是phper中的小菜鸟一只吧。由于刚开始学的时候没有名师指,碰过不少疙瘩,呗很多小问题卡过很久,白白浪费不少宝贵的时间,在次分享一些子的学习的心得。
作者: 若相依    时间: 2015-3-5 03:41
最后祝愿,php会给你带来快乐的同时 你也会给他带来快乐。
作者: 谁可相欹    时间: 2015-3-10 12:08
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
作者: 海妖    时间: 2015-3-11 13:23
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 透明    时间: 2015-3-11 16:32
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
作者: 飘灵儿    时间: 2015-3-19 01:20
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
作者: 莫相离    时间: 2015-3-19 16:10
兴趣是最好的老师,百度是最好的词典。
作者: 不帅    时间: 2015-3-20 13:34
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
作者: 蒙在股里    时间: 2015-3-22 05:10
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
作者: 因胸联盟    时间: 2015-3-29 15:09
当留言板完成的时候,下步可以把做1个单人的blog程序,做为目标,
作者: 冷月葬花魂    时间: 2015-4-4 19:30
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 柔情似水    时间: 2015-4-6 02:18
当然这种网站的会员费就几十块钱。
作者: 老尸    时间: 2015-4-14 13:07
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 山那边是海    时间: 2015-4-21 18:21
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
作者: admin    时间: 2015-4-30 17:21
基础有没有对学习php没有太大区别,关键是兴趣。
作者: 活着的死人    时间: 2015-5-9 04:44
写的比较杂,因为我也是个新手,不当至于大家多多指正。
作者: 简单生活    时间: 2015-7-3 02:05
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2