利用PHP如何查看邮件是否已被阅读

发布时间:2020-12-11 15:11:59 作者:Leah
来源:亿速云 阅读:208

利用PHP如何查看邮件是否已被阅读?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

一.查看邮件是否已被阅读
      
当你发送邮件时,你肯定很想知道你的邮件是否已被对方查看。下面的代码就能实现记录阅读你邮件的IP地址,还有实际的阅读日期和时间。

代码如下:

error_reporting(0);Header("Content-Type: image/jpeg");//Get IPif (!empty($_SERVER['HTTP_CLIENT_IP'])){  $ip=$_SERVER['HTTP_CLIENT_IP'];}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{  $ip=$_SERVER['REMOTE_ADDR'];}//Time$actual_time = time();$actual_day = date('Y.m.d', $actual_time);$actual_day_chart = date('d/m/y', $actual_time);$actual_hour = date('H:i:s', $actual_time);//GET Browser$browser = $_SERVER['HTTP_USER_AGENT'];    //LOG$myFile = "log.txt";$fh = fopen($myFile, 'a+');$stringData = $actual_day . ' ' . $actual_hour . ' ' . $ip . ' ' . $browser . ' ' . "\r\n";fwrite($fh, $stringData);fclose($fh);//Generate Image (Es. dimesion is 1x1)$newimage = ImageCreate(1,1);$grigio = ImageColorAllocate($newimage,255,255,255);ImageJPEG($newimage);ImageDestroy($newimage);?>

 
二.从网页中提取关键词

这段优秀的代码可以简单地实现从网页中提取关键词的功能。

代码如下:

$meta = get_meta_tags('http://www.emoticode.net/');
$keywords = $meta['keywords'];
// Split keywords
$keywords = explode(',', $keywords );
// Trim them
$keywords = array_map( 'trim', $keywords );
// Remove empty values
$keywords = array_filter( $keywords );
print_r( $keywords );

三.查找页面上的所有链接

使用DOM,你可以在任意页面上抓取链接,示例如下。

代码如下:

$html = file_get_contents('http://www.php100.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
       $href = $hrefs->item($i);
       $url = $href->getAttribute('href');
       echo $url.'';
}

 四.自动转换URL为可点击超链接
      
在Wordpress中,如果你想自动转换所有的URLs为可点击超链接,你就可以使用内置函数make_clickable()实现。当你在WordPress外操作时,你可以参考wp-includes/formatting.php中的源代码。

代码如下:

function _make_url_clickable_cb($matches) {
    $ret = '';
    $url = $matches[2];
 
    if ( empty($url) )
         return $matches[0];
    // removed trailing [.,;:] from URL
    if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
        $ret = substr($url, -1);
        $url = substr($url, 0, strlen($url)-1);
    }
    return $matches[1] . "$url" . $ret;
}
 
function _make_web_ftp_clickable_cb($matches) {
    $ret = '';
    $dest = $matches[2];
    $dest = 'http://' . $dest;
 
    if ( empty($dest) )
        return $matches[0];
    // removed trailing [,;:] from URL
    if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
        $ret = substr($dest, -1);
        $dest = substr($dest, 0, strlen($dest)-1);
    }
    return $matches[1] . "$dest" . $ret;
}
 
function _make_email_clickable_cb($matches) {
    $email = $matches[2] . '@' . $matches[3];
    return $matches[1] . "$email";
}
 
function make_clickable($ret) {
    $ret = ' ' . $ret;
    // in testing, using arrays here was found to be faster
    $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)     #is', '_make_url_clickable_cb', $ret);
    $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
    $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
 
// this one is not in an array because we need it to run last, for cleanup of accidental links within links
    $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret);
    $ret = trim($ret);
    return $ret;
}

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

推荐阅读:
  1. 邮件阅读状态跟踪
  2. php查看是否在线的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:利用PHP怎么实现一个短信发送功能

下一篇:phpmyadmin中出现“The mbstring ext.....”报错如何解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》