opcodesio / mail-parser
无需mailparse扩展即可解析电子邮件
v0.1.6
2023-11-19 08:47 UTC
Requires
- php: ^8.0
Requires (Dev)
- pestphp/pest: ^2.16
- symfony/var-dumper: ^6.3
README
PHP电子邮件解析器
简单、快速、无需扩展
特性
OPcodes的 邮件解析器 提供一个简单的API来解析电子邮件及其MIME内容。与许多其他解析器不同,此包不需要mailparse PHP扩展。
未完全测试RFC 5322。
开始使用
要求
- PHP 8.0+
安装
要使用Composer安装此包,请运行
composer require opcodesio/mail-parser
用法
use Opcodes\MailParser\Message; // Parse a message from a string $message = Message::fromString('...'); // Or from a file location (accessible with file_get_contents()) $message = Message::fromFile('/path/to/email.eml'); $message->getHeaders(); // get all headers $message->getHeader('Content-Type'); // 'multipart/mixed; boundary="----=_Part_1_1234567890"' $message->getFrom(); // 'Arunas <arunas@example.com> $message->getTo(); // 'John Doe <johndoe@example.com> $message->getSubject(); // 'Subject line' $message->getDate(); // DateTime object when the email was sent $message->getSize(); // Email size in bytes $message->getParts(); // Returns an array of \Opcodes\MailParser\MessagePart, which can be html parts, text parts, attachments, etc. $message->getHtmlPart(); // Returns the \Opcodes\MailParser\MessagePart containing the HTML body $message->getTextPart(); // Returns the \Opcodes\MailParser\MessagePart containing the Text body $message->getAttachments(); // Returns an array of \Opcodes\MailParser\MessagePart that represent attachments $messagePart = $message->getParts()[0]; $messagePart->getHeaders(); // array of all headers for this message part $messagePart->getHeader('Content-Type'); // value of a particular header $messagePart->getContentType(); // 'text/html; charset="utf-8"' $messagePart->getContent(); // '<html><body>....' $messagePart->getSize(); // 312 $messagePart->getFilename(); // name of the file, in case this is an attachment part
贡献
正在编写贡献指南...
安全漏洞
请查看我们如何报告安全漏洞的安全策略。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。