仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3324|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页设计PHP教程.使用实例10

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-16 00:29:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
熟悉了PHP和MYSQL开发的要领之后,再回头看你写的那个留言本,你也许会怀疑那真的是你写的吗?当然,如果屋里还有鬼的话,也许是它写的-_-教程|使用实例   php写的发送附件的法式(二)
<?php
class html_mime_mail{

var $headers;
var $body;
var $multipart;
var $mime;
var $html;
var $html_text;
var $html_images = array();
var $cids = array();
var $do_html;
var $parts = array();

/***************************************
** Constructor function. Sets the headers
** if supplied.
***************************************/
function html_mime_mail($headers = ''){
$this->headers = $headers;
}

/***************************************
** Adds a html part to the mail.
** Also replaces image names with
** content-id's.
***************************************/
function add_html($html, $text){
$this->do_html = 1;
$this->html = $html;
$this->html_text = $text;
if(is_array($this->html_images) AND count($this->html_images) > 0){
for($i=0; $i<count($this->html_images); $i++){
$this->html = ereg_replace($this->html_images[$i]['name'], 'cid:'.$this->html_images[$i]['cid'], $this->html);
}
}
}

/***************************************
** Builds html part of email.
***************************************/
function build_html($orig_boundary){
$sec_boundary = '=_'.md5(uniqid(time()));
$thr_boundary = '=_'.md5(uniqid(time()));

if(!is_array($this->html_images)){
$this->multipart.= '--'.$orig_boundary."\r\n";
$this->multipart.= 'Content-Type: multipart/alternative; boundary="'.$sec_boundary."\"\r\n\r\n\r\n";

$this->multipart.= '--'.$sec_boundary."\r\n";
$this->multipart.= 'Content-Type: text/plain'."\r\n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."\r\n\r\n";
$this->multipart.= $this->html_text."\r\n\r\n";

$this->multipart.= '--'.$sec_boundary."\r\n";
$this->multipart.= 'Content-Type: text/html'."\r\n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."\r\n\r\n";
$this->multipart.= $this->html."\r\n\r\n";
$this->multipart.= '--'.$sec_boundary."--\r\n\r\n";
}else{
$this->multipart.= '--'.$orig_boundary."\r\n";
$this->multipart.= 'Content-Type: multipart/related; boundary="'.$sec_boundary."\"\r\n\r\n\r\n";

$this->multipart.= '--'.$sec_boundary."\r\n";
$this->multipart.= 'Content-Type: multipart/alternative; boundary="'.$thr_boundary."\"\r\n\r\n\r\n";

$this->multipart.= '--'.$thr_boundary."\r\n";
$this->multipart.= 'Content-Type: text/plain'."\r\n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."\r\n\r\n";
$this->multipart.= $this->html_text."\r\n\r\n";

$this->multipart.= '--'.$thr_boundary."\r\n";
$this->multipart.= 'Content-Type: text/html'."\r\n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."\r\n\r\n";
$this->multipart.= $this->html."\r\n\r\n";
$this->multipart.= '--'.$thr_boundary."--\r\n\r\n";

for($i=0; $i<count($this->html_images); $i++){
$this->multipart.= '--'.$sec_boundary."\r\n";
$this->build_html_image($i);
}

$this->multipart.= "--".$sec_boundary."--\r\n\r\n";
}
}
/***************************************
** Adds an image to the list of embedded
** images.
***************************************/
function add_html_image($file, $name = '', $c_type='application/octet-stream'){
$this->html_images[] = array( 'body' => $file,
'name' => $name,
'c_type' => $c_type,
'cid' => md5(uniqid(time())) );
}


/***************************************
** Adds a file to the list of attachments.
***************************************/
function add_attachment($file, $name = '', $c_type='application/octet-stream'){
$this->parts[] = array( 'body' => $file,
'name' => $name,
'c_type' => $c_type );
}

/***************************************
** Builds an embedded image part of an
** html mail.
***************************************/
function build_html_image($i){
$this->multipart.= 'Content-Type: '.$this->html_images[$i]['c_type'];

if($this->html_images[$i]['name'] != '') $this->multipart .= '; name="'.$this->html_images[$i]['name']."\"\r\n";
else $this->multipart .= "\r\n";

$this->multipart.= 'Content-ID: <'.$this->html_images[$i]['cid'].">\r\n";
$this->multipart.= 'Content-Transfer-Encoding: base64'."\r\n\r\n";
$this->multipart.= chunk_split(base64_encode($this->html_images[$i]['body']))."\r\n";
}

/***************************************
** Builds a single part of a multipart
** message.
***************************************/
function build_part($i){
$message_part = '';
$message_part.= 'Content-Type: '.$this->parts[$i]['c_type'];
if($this->parts[$i]['name'] != '')
$message_part .= '; name="'.$this->parts[$i]['name']."\"\r\n";
else
$message_part .= "\r\n";

// Determine content encoding.
if($this->parts[$i]['c_type'] == 'text/plain'){
$message_part.= 'Content-Transfer-Encoding: 7bit'."\r\n\r\n";
$message_part.= $this->parts[$i]['body']."\r\n";
}else{
$message_part.= 'Content-Transfer-Encoding: base64'."\r\n";
$message_part.= 'Content-Disposition: attachment; filename="'.$this->parts[$i]['name']."\"\r\n\r\n";
$message_part.= chunk_split(base64_encode($this->parts[$i]['body']))."\r\n";
}

return $message_part;
}

/***************************************
** Builds the multipart message from the
** list ($this->parts).
***************************************/
function build_message(){
$boundary = '=_'.md5(uniqid(time()));

$this->headers.= "MIME-Version: 1.0\r\n";
$this->headers.= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n";
$this->multipart = '';
$this->multipart.= "This is a MIME encoded message.\r\nCreated by html_mime_mail.class.\r\nSee http://www.heyes-computing.net/scripts/ for a copy.\r\n\r\n";

if(isset($this->do_html) AND $this->do_html == 1) $this->build_html($boundary);
if(isset($this->body) AND $this->body != '') $this->parts[] = array('body' => $this->body, 'name' => '', 'c_type' => 'text/plain');

for($i=(count($this->parts)-1); $i>=0; $i--){
$this->multipart.= '--'.$boundary."\r\n".$this->build_part($i);
}

$this->mime = $this->multipart."--".$boundary."--\r\n";
}

/***************************************
** Sends the mail.
***************************************/
function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $headers = ''){

if($to_name != '') $to = '"'.$to_name.'" <'.$to_addr.'>';
else $to = $to_addr;
if($from_name != '') $from = '"'.$from_name.'" <'.$from_addr.'>';
else $from = $from_addr;
$this->headers.= 'From: '.$from."\r\n";
//$this->headers.= $headers;
mail($to, $subject, $this->mime, $this->headers);
}

/***************************************
** Use this method to deliver using direct
** smtp connection. Relies upon Manuel Lemos'
** smtp mail delivery class available at:
** http://phpclasses.upperdesign.com
**
** void smtp_send( string *Name* of smtp object,
** string From address,
** array To addresses,
** array Headers,
** string The body)
***************************************/
function smtp_send($smtp_obj, $from_addr, $to_addr){
global $$smtp_obj;
$smtp_obj = $$smtp_obj;

if(substr($this->headers, -2) == "\r\n") $this->headers = substr($this->headers,0,-2);
$this->headers = explode("\r\n", $this->headers);

$smtp_obj->sendmessage($from_addr, $to_addr, $this->headers, $this->mime);
}

} // End of class.
?>

  熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作完整的网页,对元素属性达到熟悉程度
再见西城 该用户已被删除
沙发
发表于 2015-2-16 04:55:27 | 只看该作者
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
简单生活 该用户已被删除
板凳
发表于 2015-2-17 12:55:38 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
海妖 该用户已被删除
地板
发表于 2015-3-2 16:41:03 | 只看该作者
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。
谁可相欹 该用户已被删除
5#
发表于 2015-3-11 04:38:40 | 只看该作者
基础有没有对学习php没有太大区别,关键是兴趣。
6#
发表于 2015-3-11 12:58:57 | 只看该作者
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
乐观 该用户已被删除
7#
发表于 2015-3-11 13:17:59 | 只看该作者
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
山那边是海 该用户已被删除
8#
发表于 2015-3-18 12:43:15 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
小妖女 该用户已被删除
9#
发表于 2015-3-22 02:09:22 | 只看该作者
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
金色的骷髅 该用户已被删除
10#
发表于 2015-3-24 13:47:38 | 只看该作者
建数据库表的时候,int型要输入长度的,其实是个摆设的输入几位都没影响的,只要大于4就行,囧。
莫相离 该用户已被删除
11#
发表于 2015-4-4 09:19:26 | 只看该作者
在我安装pear包的时候老是提示,缺少某某文件,才发现 那群extension 的排列是应该有一点的顺序,而我安装的版本的排序不是正常的排序。没办法我只好把那群冒号加了上去,只留下我需要使用的扩展。
愤怒的大鸟 该用户已被删除
12#
发表于 2015-4-17 11:44:13 | 只看该作者
php是动态网站开发的优秀语言,在学习的时候万万不能冒进。在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理。
第二个灵魂 该用户已被删除
13#
发表于 2015-5-1 18:10:34 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
冷月葬花魂 该用户已被删除
14#
发表于 2015-5-11 06:53:31 | 只看该作者
当留言板完成的时候,下步可以把做1个单人的blog程序,做为目标,
只想知道 该用户已被删除
15#
发表于 2015-5-11 10:12:55 | 只看该作者
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
深爱那片海 该用户已被删除
16#
发表于 2015-5-11 21:10:09 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
admin 该用户已被删除
17#
发表于 2015-6-6 03:03:54 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
灵魂腐蚀 该用户已被删除
18#
发表于 2015-6-12 22:54:51 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
精灵巫婆 该用户已被删除
19#
发表于 2015-6-30 09:53:07 | 只看该作者
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
再现理想 该用户已被删除
20#
发表于 2015-7-4 10:53:32 | 只看该作者
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-2 05:27

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表