定制 sourcepot/email 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sourcepot/email

最新稳定版本:v1.0.0

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
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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