首页 > 编程知识 正文

php的imap库(PHP教程 PHP api类库)

时间:2023-11-29 12:18:47 阅读:310127 作者:WWLL

本文目录一览:

  • 1、如何扩展PHP的IMAP模块
  • 2、如何用PHP里的IMAP函数,实现邮件的发送,希
  • 3、php IMAP读取邮件信息
  • 4、PHP的IMAP交换问题问题,怎么解决
  • 5、PHP加载IMAP模块问题
  • 6、php编译安装后如何安装IMAP扩展

如何扩展PHP的IMAP模块

如果对php进行模块扩展,重新编译PHP,这个过程比较痛苦,我的方法都是采用编译模块为*.so的方式,简单,方便,不用去其他地方找模块源码包,php源码自带了。

1、进入安装目录

cd /path/ext/imap

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config

就是到这步报错了,如果你碰到这样的错误:

This c-client library is built with Kerberos support.

Add --with-kerberos to your configure line. Check config.log for details

utf8_mime2text() has new signature

以上2个错误都是由于缺少 libc-client-* 软件包引起,由于我是Centos系统,就直接yum升级吧

yum -y install libc-client-*

安装完毕后,再次编译,

./configure --with-php-config=/usr/local/webserver/php/bin/php-config

这次的错误不一样,如下:

configure: error: Kerberos libraries not found.

Check the path given to --with-kerberos (if no path is given, searches in /usr/kerberos, /usr/local and /usr )

既然提示少参数,就加上该参数吧,

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-kerberos=/usr

注意:这里有3个路径可以选择,于是就一个一个试一下,很幸运的是前面2个都不能编译通过,只有 --with-kerberos=/usr 可以,但是还是有报错,如下:

This c-client library is built with SSL support

看来离希望越来越近了,于是就加上 --with-imap-ssl=/usr 参数,终于编译通过了,真不容易。

最后完整的编译 imap 模块参数如下:

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-kerberos=/usr --with-imap-ssl=/usr

make

make install

如何用PHP里的IMAP函数,实现邮件的发送,希

//以腾讯企业邮箱做了测试

$mailServer="imap.exmail.qq.com"; //IMAP主机

$mailLink="{{$mailServer}:143}INBOX" ; //imagp连接地址:不同主机地址不同

$mailUser = '***'; //邮箱用户名

$mailPass = '***'; //邮箱密码

$mbox = imap_open($mailLink,$mailUser,$mailPass); //开启信箱imap_open

$totalrows = imap_num_msg($mbox); //取得信件数

for ($i=1;$i$totalrows;$i++){

  $headers = imap_fetchheader($mbox, $i); //获取信件标头

  $headArr = matchMailHead($headers); //匹配信件标头

  $mailBody = imap_fetchbody($mbox, $i, 1); //获取信件正文

}

/**

 *

 * 匹配提取信件头部信息

 * @param String $str

 */

function matchMailHead($str){

  $headList = array();

  $headArr = array(

    'from',

    'to',

    'date',

    'subject'

  );

  foreach ($headArr as $key){

    if(preg_match('/'.$key.':(.*?)[nr]/is', $str,$m)){

      $match = trim($m[1]);

      $headList[$key] = $key=='date'?date('Y-m-d H:i:s',strtotime($match)):$match;

    }

  }

  return $headList;

}

php IMAP读取邮件信息

?php

$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "xxxx@gmail.com", "xxxx") or die("can't connect: " . imap_last_error());

$emails = imap_search($mbox,'ALL');

ini_set("max_execution_time",300);

if($emails) {

rsort($emails);

foreach($emails as $email_number) {

$overview = imap_fetch_overview($mbox,$email_number,0);

$pos = explode('@',$overview[0]-from);

$phone = substr($pos[0],-11); // 发件人手机号码

$struct = imap_fetchstructure($mbox, $email_number);

print_r($struct);

$parts = $struct-parts;

$i = 0;

if (!$parts) { /* Simple message, only 1 piece */

$attachment = array(); /* No attachments */

$content = imap_body($mbox, $email_number);

} else { /* Complicated message, multiple parts */

$endwhile = false; $stack = array(); /* Stack while parsing message */

$content = ""; /* Content of message */

$attachment = array(); /* Attachments */ while (!$endwhile) {

if (!$parts[$i]) {

if (count($stack) 0) {

$parts = $stack[count($stack)-1]["p"];

$i = $stack[count($stack)-1]["i"] + 1;

array_pop($stack);

} else {

$endwhile = true;

}

}

if (!$endwhile) {

/* Create message part first (example '1.2.3') */

$partstring = "";

foreach ($stack as $s) {

$partstring .= ($s["i"]+1) . ".";

}

$partstring .= ($i+1);

$file_data = imap_fetchbody($mbox, $email_number, $partstring);

$attachment[] = array("filename" =$parts[$i]-parameters[0]-value,

"filedata" = $file_data

);

if($parts[$i]-subtype == 'JPEG')

{

$file_name = md5(time().rand(5,200)).'.jpg';

file_put_contents($file_name,base64_decode($file_data));

}elseif($parts[$i]-subtype == 'GIF'){

$file_name = md5(time().rand(5,200)).'.gif';

file_put_contents($file_name,base64_decode($file_data));

}elseif($parts[$i]-subtype == 'PLAIN'){

$txt_name = time().rand(5,200).'.txt';

file_put_contents($txt_name,base64_decode($file_data));

}

}

if ($parts[$i]-parts) {

$stack[] = array("p" = $parts, "i" = $i);

$parts = $parts[$i]-parts;

$i = 0;

} else {

$i++;

}

} /* while */

} /* complicated message */

echo "userphone $phone, result:

";

echo "Content: $content

";

echo "Attachments:"; var_dump($attachment);

echo "br/br/---------------------------------------------------------------------br/br/";

}

}

imap_close($mbox);

?

PHP的IMAP交换问题问题,怎么解决

用get_extension_funcs("imap"); 函数进行测试,若返回boolean值为空,说明php_imap.dll文件没有加载进去!

PHP加载IMAP模块问题

extension_loaded("imap");

用get_extension_funcs("imap"); 函数进行测试,若返回boolean值为空,说明php_imap.dll文件没有加载进去,

php编译安装后如何安装IMAP扩展

今天程序员在最近实施的项目中需要增加IMAP验证,今天历史原因,公司很多服务器的linux操作系统及各应用程序版本都不一样,安装路径也很杂乱,再加上刚接手服务器不久,导致今天在安装IMAP的PHP扩展时,走了很多弯路;帮把今天的操作经理写下来供大家参考学习及备忘之。

环境:

[root@bjdx246 lib]# lsb_release -a

LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch

Distributor ID: RedHatEnterpriseServer

Description: Red Hat Enterprise Linux Server release 5.4 (Tikanga)

Release: 5.4

Codename: Tikanga

[root@bjdx246 lib]# php -v

PHP 5.2.5 (cli) (built: May 29 2013 16:49:51)

Copyright (c) 1997-2007 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

[root@bjdx246 /]# rpm -qa |grep php

php-ldap-5.1.6-43.el5_10

php-cli-5.1.6-43.el5_10

php-common-5.1.6-43.el5_10

再使用phpinfo.php 查看PHP相关信息后,开始安装php-imap,步骤如下:

cd /usr/local/src/php-5.2.5/ext/imap

yum -y install libc-client-*

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-kerberos --with-imap-ssl

make

make install

完成后,屏幕上会有提示/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 目录下多出一个 imap.so的文件;在上面编译过程中,出现很多报错,根据报错一个百度找答案即可;

编辑 /usr/local/php/lib/php.ini ; 添加一行 extension=imap.so

最后 重启 apache 服务搞定!

注:上面的路径是本台服务器的相关路径,其它的服务器需要根据您的实际情况进行更改,理解整个部署的思路即可哈!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。