本文目录一览:
有php 接收邮件的代码吗 注意是接收哦
接收邮件可以的,直接上代码
?php
$server = "{bjmail.*.com/pop3}"; //邮件服务器
$mailbox = "inbox"; //收件箱
$mailaccount="zhao**";//用户名
$mailpasswd=" "; //密码
$stream = @imap_open($server.$mailbox,$mailaccount,$mailpasswd);//打开IMAP 连结
$mail_number = imap_num_msg($stream);//信件的个数
if($mail_number 1) { echo "No Message for $email"; }//如果信件数为0,显示信息
for($i=$mail_number;$i=$mail_number;$i--)
{
$headers = @imap_header($stream, $i);
$mail_header= imap_headerinfo($stream, $i);//邮件头部
//var_dump ($mail_header);
$subject = $mail_header-subject;//邮件标题
$subject=decode_mime($subject);
echo $subject;
//编码为简体中文的标题的处理方法
// if(stristr($subject, "=?gb2312"))
// { //编码为简体中文的标题
// $subject=substr($subject,11);
// $subject=substr($subject,0,-2);
// $subject = base64_decode($subject);
// }
echo $from = $mail_header-fromaddress;//发件人
echo $date = $mail_header-date;//日期
$body = imap_fetchbody($stream, $i, 1);
$body = imap_base64($body);
$body = nl2br($body);
echo $body;
// $body = imap_qprint($body);
// echo $body;
// $body = imap_binary($body);
// $body = imap_base64($body);
//echo $body;
}
function decode_mime($string)
{
$pos = strpos($string,'=?');
if (!is_int($pos)) {
return $string;
}
$preceding = substr($string, 0, $pos); // save any preceding text
$search = substr($string, $pos+2); /* the mime header spec says this is the longest a single encoded Word can be */ -pop3获取邮件php
$d1 = strpos($search, '?');
if (!is_int($d1)) {
return $string;
}
$charset = substr($string, $pos+2, $d1); //取出字符集的定义部分
$search = substr($search, $d1+1); //字符集定义以后的部分=$search;
$d2 = strpos($search, '?');
if (!is_int($d2)) {
return $string;
}
$encoding = substr($search, 0, $d2); ////两个? 之间的部分编码方式 :q 或 b
$search = substr($search, $d2+1);
$end = strpos($search, '?='); //$d2+1 与 $end 之间是编码了 的内容:= $endcoded_text;
if (!is_int($end)) {
return $string;
}
$encoded_text = substr($search, 0, $end);
$rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6)); //+6 是前面去掉的 =????= 六个字符 -pop3获取邮件php
switch ($encoding) {
case 'Q':
case 'q':
//$encoded_text = str_replace('_', '%20', $encoded_text);
//$encoded_text = str_replace('=', '%', $encoded_text);
//$decoded = urldecode($encoded_text);
$decoded=quoted_printable_decode($encoded_text);
if (strtolower($charset) == 'windows-1251') {
$decoded = convert_cyr_string($decoded, 'w', 'k');
}
break;
case 'B':
case 'b':
$decoded = base64_decode($encoded_text);
if (strtolower($charset) == 'windows-1251') {
$decoded = convert_cyr_string($decoded, 'w', 'k');
}
break;
default:
$decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?=';
break;
}
return $preceding . $decoded .decode_mime($rest);
//return $preceding . $decoded . $this-decode_mime($rest);
}
怎么用PHP收POP3邮件?
给你一个用 PEAR 的类库的例子:
?php
require_once('Net/POP3.php');
$pop3 = new Net_POP3;
$pop3-connect('localhost', 110);
$pop3-login('popuser', 'poppassword', false);
$msgCnt = $pop3-numMsg();
$headers = $pop3-getParsedHeaders($msgCnt);
$from = mb_decode_mimeheader($headers['From']);
$subject = mb_decode_mimeheader($headers['Subject']);
$content = $pop3-getBody($msgCnt);
$pop3-disconnect();
echo "From: $from\n";
echo "Subject: $subject\n";
echo "Body: $content\n";
?
安装类库的命令
pear install Net_Pop3
PHP 怎么用POP3来收邮件
进入php源程序目录中的ext目录中,这里存放着各个扩展模块的源代码,选择你需要的模块,比如curl模块:cd curl
执行phpize生成编译文件,phpize在PHP安装目录的bin目录下
/usr/local/php5/bin/phpize
运行时,可能会报错:Cannot find autoconf. Please check your autoconf installation and
the $PHP_AUTOCONF
environment variable is set correctly and then rerun this
script.,需要安装autoconf:
yum install autoconf(RedHat或者CentOS)、apt-get install
autoconf(Ubuntu Linux)
/usr/local/php5/bin/php -v
执行这个命令时,php会去检查配置文件是否正确,如果有配置错误,
这里会报错,可以根据错误信息去排查!
PHP怎么用POP3来收邮件
给你一个用 PEAR 的类库的例子:
?php
require_once('Net/POP3.php');
$pop3 = new Net_POP3;
$pop3-connect('localhost', 110);
$pop3-login('popuser', 'poppassword', false);
$msgCnt = $pop3-numMsg();
$headers = $pop3-getParsedHeaders($msgCnt);
$from = mb_decode_mimeheader($headers['From']);
$subject = mb_decode_mimeheader($headers['Subject']);
$content = $pop3-getBody($msgCnt);
$pop3-disconnect();
echo "From: $from\n";
echo "Subject: $subject\n";
echo "Body: $content\n";
?
安装类库的命令
pear install Net_Pop3