国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 PHP郵件收發(fā),和編碼問題。數據匹配

PHP郵件收發(fā),和編碼問題。數據匹配

Jun 06, 2016 pm 08:00 PM
head php match data coding mail question

?php header("content-type:text/html; charset=UTF-8"); /* * record kid words and insert into database * user by sending email to publication kid words * */ include 'POP3.php'; include 'email_class.php'; include 'Mail_mimeDecode.php'; //incl

header("content-type:text/html; charset=UTF-8");
/*
?* record kid words and insert into database
?* user by sending email to publication kid words
?*
?*/
include 'POP3.php';
include 'email_class.php';
include 'Mail_mimeDecode.php';
//include 'include/compatible.php';
include 'include/extend_common.php';
//include '../../htdocs/include/extend_common.php';
define('POST_FROM_EMAIL',???1);
define('DATABASE_CONNECTION_ERROR',?2);//數據庫連接失敗錯誤
define('EMAIL_CONNECTION_ERROR',?3);//郵箱連接失敗錯誤
define('ACCOUNT_ERROR',????4);//郵箱的賬號錯誤
define('SIGN_EMAIL_ERROR',???5);//郵件標記刪除錯誤
define('DELELET_ERROR',????6);//刪除郵件錯誤
define('INSERT_ERROR',????7);//插入數據失敗錯誤

class mail_data {

?function mail_data(){
??include 'config.php';??
??$mail_log=fopen("mail_log.txt","a+");
??$conn=@mysql_connect($db_host,$db_user,$db_password);
??if($conn){
???mysql_select_db('t',$conn);
???mysql_query("set names utf8");
???$pop3=new Net_POP3();
???//判斷連接是否成功
???if ($pop3->connect($host,110)){
????//判斷登入是否成功
????if($pop3->login($user,$password)===true){
?????$list=$pop3->_cmdList();
?????$sum=$pop3->_cmdStat();

?????//每次取多少郵件
?????$step=2;
?????$r=0;
?????//先對郵箱取$step郵件
?????for($n=0;$n??????$t=0;
??????$users=array();
??????$mail=array();
??????$offset=($sum[0]-$n)??????//郵件循環(huán)
??????for ($i=$r;$i

???????//取得郵件信息
???????$user=$this->one_mail($i,$pop3,$list,$mail_log);
???????array_push($mail,$user['from_mail']);
???????array_push($users,$user);
???????$r=$i+1;
??????}
??????//取得mail用戶數據
??????$str=$this->uesr_data($mail);
??????$value=array();

??????//當前郵件數組循環(huán),當前郵件用戶的email,小孩名,童言
??????for ($m=0;$m???????$num=0;
???????$mn=$m+$n;
???????//數據處理
???????$post_text=$users[$m]['conntent'];
???????if(!empty($post_text)){
????????$post_text=do_submit_text($post_text);
????????$post_text=mysql_real_escape_string($post_text);
????????$post_link_num=parsed_text_include_links($post_text);
????????$text=do_submit_text($post_text);
????????$post_text_undo=mysql_real_escape_string($text);
????????$post_text=mysql_real_escape_string($post_text);
????????$val=array();
????????$kid_num=$users[$m]['kid_nickname'];
????????if(is_numeric($kid_num) && intval($kid_num)0){
?????????$kid_num=intval($kid_num);
?????????$val=$this->kid_data($users,$m,$kid_num,$post_text,$post_link_num,$post_text_undo);
?????????if(isset($val)){
??????????$value["$t"]=$val;
??????????$num=1;
??????????$t=$t+1;
?????????}
????????}else{
????????//數據庫中的數據
????????for($x=0;$x?????????//判斷是否是from_mail的小孩
?????????$val["$x"]=
?????????$this->is_kid($users,$str,$m,$x,$post_text,$post_link_num,$post_text_undo);
?????????if(isset($val["$x"])){
??????????$value["$t"]=$val["$x"];
??????????$num=1;
??????????$t=$t+1;
?????????}
????????}
????????}

????????//判斷是否成功與數據庫中數據匹配到
????????if($num==0){
?????????$val=$this->kid_data($users,$m,1,$post_text,$post_link_num,$post_text_undo);
?????????if(isset($val)){
??????????$value["$t"]=$val;
??????????$num=1;
??????????$t=$t+1;
?????????}
????????}
???????}
??????}
??????//對一段數據操作
??????$valu=implode("),(",$value);??????
??????if($valu!=""){
???????$err_time=$this->insert_date($valu);
???????$this->kid_message_count($value);
??????}
?????}?????
?????fclose($mail_log);
?????/*
?????if($pop3->disconnect()==false){
?????? $this->_error(DELELET_ERROR);??????
?????}
?????*/
????}else{
?????echo "帳號或密碼錯誤!";
?????$this->_error(ACCOUNT_ERROR);
????}
???}else {
????echo "連接失敗...";
????$this->_error(EMAIL_CONNECTION_ERROR);;
???}
??}else{???
???echo "數據庫連接失敗...";
???$this->_error(DATABASE_CONNECTION_ERROR);
??}
?}
/*
?*read the $i email message
?*@access public
?*@param? int $i mail id
?*@param? object $pop3? pop3 protocol object
?*@return array? mail from ,header,content
?*/
function one_mail($i,$pop3,$list,$mail_log){
??$stg=$pop3->getParsedHeaders($list[$i]['msg_id']);
??$from=imap_mime_header_decode($stg['From']);//郵件的發(fā)送者
??$string_from='';
??for ($j=0;$j???$string_from="$string_from".$from[$j]->text;
??}
??preg_match("/([a-z0-9A-Z_]+)@([a-z0-9A-Z/.]+).([a-z0-9A-Z]+)/",$string_from,$from_mail);

??$string=$pop3->getMsg($list[$i]['msg_id']);
??$body=new Mail_mimeDecode($string);

??$sr=$body->decode(array('include_bodies' => true,'decode_bodies'=>false,'decode_headers'=>true));

??if(property_exists($sr,'parts')){
???$mail_part=$sr->parts;
???$mail_part=$mail_part[0];
??}else{
???$mail_part=$sr;
??}

??$mail_code=$mail_part->headers;
??$mail_code=$mail_code['content-transfer-encoding'];//編碼格式
??$mail_type=$mail_part->ctype_parameters;
??$mail_type=$mail_type['charset'];
??$mail_body=$mail_part->body;//正文內容

??if($mail_code=="base64"){//判斷編碼格式
???$text=base64_decode("$mail_body");
???$text=iconv("$mail_type","UTF-8",$text);
??}else{
???$text=quoted_printable_decode("$mail_body");
???$text=iconv("$mail_type","UTF-8",$text);
??}

??$mail_title=$sr->headers;
??$mail_title=$mail_title['subject'];
??$mail_title=imap_mime_header_decode($mail_title);

??if(count($mail_title)!=0){

???$title=$mail_title[0]->text;
???$t=$mail_title[0]->charset;

???if($t!="default"){
????$title=iconv($t,"UTF-8",$title);
???}else{
????$title=iconv("gb2312","UTF-8",$title);
???}
??}else{
???$title=1;
??}
??//$pop3->_cmdDele($list[$i]['msg_id']);
??$pop3->deleteMsg($list[$i]['msg_id']);
??if($pop3->deleteMsg($list[$i]['msg_id'])==false){
???$this->_error(SIGN_EMAIL_ERROR);
??}
??//取得需要插入的用戶email,小孩名,童言
??$users["$i"]=array("from_mail"=>"$from_mail[0]","kid_nickname"=>"$title","conntent"=>"$text","body_type"=>"$mail_type");
??$log=$users["$i"];
??array_unshift($log,date("Y-m-d H:i;s"));
??$log=serialize($log);
??fwrite($mail_log,$log."/r/n");
??return $users["$i"];
??}
/**
?*at database search $mail user's information
?*@access public
?*@param string $mail all email
?*@return array mail user's information
?*/
function uesr_data($mail){
?$mails=implode("','",$mail);
?$sql="SELECT? a.mail,a.user_name,a.user_nickname,b.kid_id, b.kid_name,b.kid_avatar ,b.kid_birthday
??FROM `t_users` a, `t_users_kid` b
??WHERE a.mail in ('$mails') AND a.user_id=b.user_id";
?$query=mysql_query($sql)or die(mysql_error());
?$str1=array();

?while($arr=mysql_fetch_array($query)){
??array_push($str1,$arr);
?}
?return $str1;
}
/*
?*insert $value into database
?*@access public
?*@param string $value kid information
?*@return void
?*/
function insert_date($value){
?$sql_insert="INSERT INTO `t_posts`(kid_id,user_name,user_nickname,post_time,post_text,user_avatar,post_link_num,post_text_undo,post_from,add_time)
?VALUES ($value)";
?$num=mysql_query($sql_insert)or die(mysql_error());

?if($num!=1){
??$this->_error(INSERT_ERROR);
?}
}
/*
?*send email to $smtpemailto
?*@access public
?*@param string $mailtype mail_from type
?*@param string $smtpemailto mail_from
?*@param string $user_kid_name mail title
?*@return void
?*/
function reply_email($mailtype,$smtpemailto,$user_kid_nickname){
?require "config.php";
?$mailsubject = "您暫時還沒有".$user_kid_nickname."寶寶";
?$mailsubject = "=?UTF-8?B?".base64_encode($mailsubject)."?=";
?$mailbody = "請先添加寶寶";

?if($mailtype!="ISO-8859-1"){
??$mailbody=iconv("utf-8","$mailtype//ignore",$mailbody);
?}

?$mail_type = "HTML";
?$smtp=new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
?$smtp->debug = FALSE;
?$send_mail=$smtp->sendmail($smtpemailto,$smtpusermail,$mailsubject, $mailbody, $mail_type,"","");

?if($send_mail==false){
??return? "send faile";
??$send_mail=$smtp->sendmail($smtpemailto,$smtpusermail,$mailsubject, $mailbody, $mail_type,"","");
?}
}
/*
?*the kid's age then publication kid words
?*@access public
?*@param int $kid_birthday kid birthday
?*@return array kid year month day
?*/

function get_kid_age_info($kid_birthday){
?$cur_date=date("Ymd");
?$age=$cur_date-$kid_birthday;
?if($age??return false;
?}
?$years=0;
?$months=0;
?$days=0;
?if($age>10000){
??$years=floor($age/10000);
?}

?$age=$age%10000;
?$months=floor($age/100);
?if($months>12)$months-=88;
??$days=$age % 100;
??if($days>$cur_date%100){
???$days=$days-(100-date("d", strtotime(date("Ym")."01")-24*3600));
??}
?return array($years, $months, $days);
}
/**
?*judge the $m message and? the $x data
?*@access public
?*@param array $users mail information
?*@param array $str user information
?*@param int $m? $users grade
?*@param int $x? $str? grade
?*@param string $post_text the mail text
?*@return string? information
?*/
function is_kid($users,$str,$m,$x,$post_text,$post_link_num,$post_text_undo){

?if($users[$m]['from_mail']==$str[$x]['mail']){//判斷是否是from_mail的小孩

??$kid_id=$str[$x]['kid_id'];
??$user_name=$str[$x]['user_name'];
??$user_nickname=$str[$x]['user_nickname'];
??$kid_diff=$str[$x]['kid_birthday'];
??$kid_name=$str[$x]['kid_name'];
??$kid_diff=date("Ymd",$kid_diff);
??$kid_birthdy=$this->get_kid_age_info($kid_diff);
??//格式轉換
??for ($j=0;$j???if ($kid_birthdy[$j]>=0&&$kid_birthdy[$j]????$kid_birthdy[$j]="0"."$kid_birthdy[$j]";
???}
??}
??$post_time=$kid_birthdy[0].$kid_birthdy[1].$kid_birthdy[2];
??$user_avatar=get_kid_avatar($user_name,$kid_id);
??$kid_avatar=$user_avatar;
??if($users[$m]['kid_nickname']==$kid_name){
???$kid_id=mysql_real_escape_string("$kid_id");
???$user_name=mysql_real_escape_string("$user_name");
???$post_time=mysql_real_escape_string("$post_time");
???$kid_avatar=mysql_real_escape_string("$kid_avatar");
???$from=POST_FROM_EMAIL;
???$add_time=time();
???$values="'$kid_id','$user_name','$user_nickname','$post_time','$post_text','$kid_avatar','$post_link_num','$post_text_undo','$from','$add_time'";
???return $values;
??}
?}
}
/**
?*have the kid_num kid of users? information
?*@access public
?*@param array $users the array() of users
?*@param int $m the m items of array
?*@param int $kid_num the kid_num kid
?*@return array? kid information
?*/
function user_kid($users,$m,$kid_num){
?$m_mail=$users["$m"]['from_mail'];
?$sql="SELECT? a.user_name,a.user_nickname,b.kid_id, b.kid_name,b.kid_avatar ,b.kid_birthday
??FROM `t_users` a, `t_users_kid` b
??WHERE a.mail='$m_mail' AND a.user_id=b.user_id ORDER BY b.kid_birthday ASC ";
?$query=mysql_query($sql)or die(mysql_error());
?$str1=array();
?$kids=array();
?$i=0;
?while($arr=mysql_fetch_array($query)){
??$str1[$i]=$arr;
??$i=$i+1;
??}
?? $kid_num=$kid_num-1;
?? if($kid_num>(count($str1)-1)){
??? return $num=0;
?? }else{
??? return $str1["$kid_num"];
?? }

}
/**
?*get the kid_num kid information
?*@access public
?*@param array $users the array() of users
?*@param int $m the m items of array
?*@param int $kid_num the kid_num kid
?*@param string? $post_text the message of mail
?*@param int $post_link_num count(link) of message body
?*@return array? $values? the kid information
?*/
function kid_data($users,$m,$kid_num,$post_text,$post_link_num,$post_text_undo){
??$use_kid=$this->user_kid($users,$m,$kid_num);

??if($use_kid!=0){
???$kid_id=$use_kid['kid_id'];
???$user_name=$use_kid['user_name'];
???$user_nickname=$use_kid['user_nickname'];
???$kid_diff=$use_kid['kid_birthday'];
???$kid_diff=date("Ymd",$kid_diff);
???$kid_birthdy=$this->get_kid_age_info($kid_diff);
???//格式轉換
???for ($j=0;$j????if ($kid_birthdy[$j]>=0&&$kid_birthdy[$j]?????$kid_birthdy[$j]="0"."$kid_birthdy[$j]";
????}
???}
???$post_time=$kid_birthdy[0].$kid_birthdy[1].$kid_birthdy[2];

???$user_avatar=get_kid_avatar($user_name,$kid_id);
???$kid_avatar=$user_avatar;
???$add_time=time();
???$from=POST_FROM_EMAIL;
???$values="'$kid_id','$user_name','$user_nickname','$post_time','$post_text','$kid_avatar','$post_link_num','$post_text_undo','$from','$add_time'";
???return $values;
??}
}
/**
?*update data when have kid words
?*@access public
?*@param array $value the array() of users
?*@return void
?*/
function kid_message_count($value){
?$use_names=array();

?for($k=0;$k??$k_name=explode(",",$value[$k]);
??$use_names[$k]=$k_name[1];
?}
?asort($use_names);
?$sum_kid=count($use_names);
?$s=0;
?if(count($use_names)==1){
??$d_users[0]=$use_names[0];
?}
?else{

??? //第一個
?if($use_names[0]!=$use_names[1]){
??$d_users[0]=$use_names[0];
?}else{
??$s_users[$s]=$use_names[0];
??$s=$s+1;
?}
?//最后一個
?if($use_names[$sum_kid-1]!=$use_names[$sum_kid-2]){
??$d_users[$sum_kid-1]=$use_names[$sum_kid-1];
?}else{
??$s_users[$s]=$use_names[$sum_kid-1];
??$s=$s+1;
?}

?for($k=1;$k

??if($use_names[$k]==$use_names[$k-1]||$use_names[$k]==$use_names[$k+1]){
???$s_users[$s]=$use_names[$k];
???$s=$s+1;
??}else{
???$d_users[$k]=$use_names[$k];
??}

?}
?}

?if(isset($d_users)){
??$names=implode(",",$d_users);
??$sql="UPDATE `t_users` set post_num = post_num+1 WHERE `t_users`.user_name in ($names)";
??$query=mysql_query($sql)or die(mysql_error());
?}

?if(isset($s_users)){

??for($s=0;$s???$name=$s_users[$s];
???$sql="UPDATE `t_users` set post_num = post_num+1 WHERE `t_users`.user_name = $name";
???$query=mysql_query($sql)or die(mysql_error());
??}

?}

}
/**
?* point error
?*@access private
?*@param int error_num the error code
?*@return void
?*
?*/
private function _error($error_num){?
?$error_log=fopen("error_log.txt","a+");
?switch($error_num){
??case 2:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tCould not connect database!/r/n");break;
??case 3:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tConnection Failure!/r/n");break;
??case 4:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tAccount number or password error!!/r/n");break;
??case 5:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tsign email failed!/r/n");break;
??case 6:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tdelete emails failed!/r/n");break;
??case 7:fwrite($error_log,date("Y-m-d H:i:s")."/t".$error_num."/tinsert data failed!/r/n");break;??
?}
?fclose($error_log);
}
}


?>
這個類主要是為了讀取郵件服務器中郵件的信息的,并對郵件信息進行處理,提取出郵件信息中的from,title ,content
并且提取出他們的編碼格式,并對他們進行處理,同時from ,title 分別要和數據庫中的信息去匹配,one_mail函數為只讀取一封mail郵件的信息的,通過傳參數i確定是讀取第幾封mail,并且返回mail 的 from ,title,content。在這個函數當中,主要是要判斷當前的對象是否有parts屬性,所以要進行判斷,各個郵件發(fā)送郵件時候都有點差異的。編碼的提取和解碼
user_data函數主要是返回當前mail 參數中數據庫中用戶的信息,
insert_data函數,主要是把當前的當前的value 數據插入,value參數原為一個數組,后通過函數implode函數進行分解
,從而能對數據進行批插入。
reply_email函數為回復mai函數,這函數中主要的問題是要對發(fā)送過來的函數的編碼進行提取,從而當回復時也用
它發(fā)送的編碼方式,這樣才不會出現編碼的問題。
is_kid函數,為判斷小孩是否是存在,和郵件信息時候相匹配
kid_message_count函數為孩子的大小排序的,如果當前孩子比較多的話,可以為它孩子進行大小排序。

執(zhí)行這個類的話:
$file=fopen("mail.pid","a+");
if(flock($file,LOCK_EX+LOCK_NB)){?
?fwrite($file,date("Y-m-d H:i:s")."/tfile had locking/r/n");
?$mail=new mail_data();
?flock($file,LOCK_UN);
?}else{
??echo "程序運行中……";
?}
?fclose($file);

這個主要是通過文件鎖flock來處理它進行單進程運行程序。

同時在整個類中,我也對當前的郵件信息數據進行了日志記載,和錯誤信息記錄。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

See all articles