sourcepot/email 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sourcepot/email

Composer 安装命令:

composer require sourcepot/email

包简介

PHP class to convert an email into an array

关键字:

README 文档

README

This email package contains only the scanner class and a test website yet.

Scanner class

The scanner class extracts the content and headers of an e-mail that is read in as a string. The result is available as an array. The e-mail formats of the Internet Text Message Standard (e.g. Thimderbird) or OLE (e.g. Outlook) are currently supported.

First steps using the Scanner class in your project

Following code shows how an instance of the Scanner class is created and the email loaded into the scanner. The results can be retrieved using the getHeader() and getParts() methods:

$scanner = new SourcePot\Email\Scanner();
$scanner->load($email);

$emailTransferHeader = $scanner->getHeader();
$emailParts = $scanner->getParts();

The source for an email can be a file upload or an IMAP mailbox folder. In the following example, an IMAP mailbox folder is opened and "today's" emails are looped through. The emails will be represented as character strings. You will need to provide the correct {MAILBOX}, {USER} and {PASSWORD} for the email folder.

$scanner = new SourcePot\Email\Scanner();

$mbox=@imap_open({MAILBOX},{USER},{PASSWORD});

$errors=imap_errors();
// add error handling code here

$alerts=imap_alerts();
// add alarm handling code here

if (!empty($mbox)){
    $messages=imap_search($mbox,'SINCE "'.date('d-M-Y').'"');
    if ($messages){
        foreach($messages as $mid){
            $email=imap_fetchbody($mbox,$mid,"");
            $scanner->load($email);
            // add code here to process the resulting $emailParts, $emailTransferHeader
        }
    }
}    

Test website

A test website is part of the package. An e-mail can be uploaded as a file to a temporary directory via the test website and then processed by the scanner class.

To use classes of the package or the test website, you must install the package on your computer (in the web directory of your localhost). After installation, you can open the test website via your browser. The easiest way to install the package is to use Composer. First make sure that Composer is already installed and then use the command prompt to execute the installation command:

composer create-project sourcepot/email {... add target web-directory here ...}

Let's start with the following test email which contains an attachment (pdf-file):

Test email

The test email is dragged & dropped form Thunderbird into the Windows file explorer:

Test copied to a folder on the computer

The test website is opened on the localhost. Select the email and upload the email, click the "Process" button to process the email. The e-mail transfer header and each e-mail part are displayed in a separate table. The folloing screenshot shows the test result, can you see the preview of attachment?

Test email uploaded and processed

统计信息

  • 总下载量: 68
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固