onviser/mailer
Composer 安装命令:
composer require onviser/mailer
包简介
PHP library for sending email with attachments over SMTP
README 文档
README
Simple sending of emails via socket. Convenient to use on shared hosting, where there are problems with using PHP mail() function.
Install
composer require onviser/mailer
How to use
Sending simple email:
$mail = (new Mail()) ->setSubject('This is a subject') ->setBody('This is a body') ->setFrom('from@example.com') ->to('to@example.com'); $socket = new Socket('localhost', 25, 'login', 'password'); $mailer = new SendToSocketMailer($socket); if ($mailer->send($mail)) { // mail was sent } else { // error echo "error: {$mailer->getError()}" . PHP_EOL; print_r($mailer->getLog()); }
Email with copy and blind copy:
$mail = (new Mail()) ->setSubject('This is a subject') ->setBody('This is a body') ->setFrom('from@example.com') ->to('to1@example.com') ->to('to2@example.com') ->copy('copy1@example.com') ->copy('copy2@example.com') ->blindCopy('blind-copy@example.com');
Email with "Reply-To" header:
$mail = (new Mail()) ->setSubject('This is a subject') ->setBody('This is a body') ->setFrom('from@example.com') ->setReplayTo('replay-to@example.com') ->to('to@example.com');
Email with attachments:
$attachmentText = (new Attachment()) ->setFileName('file.txt') ->setFileType('text/plain') ->setData('This is a text.'); $attachmentHTML = (new Attachment()) ->setFileName('file.html') ->setFileType('text/html') ->setData('<p>This is a <strong>HTML</strong>.</p>'); $mail = (new Mail()) ->setType(Mail::TYPE_HTML) ->setSubject('This is a subject') ->setBody('<p>This is a <strong>HTML</strong> body</p>') ->setFrom('from@example.com') ->to('to@example.com') ->attachment($attachmentText) ->attachment($attachmentHTML);
Send to file (for development environment)
During development, it is convenient to use storing emails on disk instead of sending them.
$mail = (new Mail()) ->setSubject('This is a subject') ->setBody('This is a body') ->setFrom('from@example.com') ->to('to@example.com'); $mailer = new SendToFileMailer('../var/mail/'); if ($mailer->send($mail)) { // mail was saved } else { // error echo "error: {$mailer->getError()}" . PHP_EOL; }
Tests
./vendor/bin/phpunit
./vendor/bin/phpstan
PHP-библиотека для отправки электронной почты с вложениями по SMTP
Простая отправка электронных писем через сокет. Удобна для использования на виртуальном хостинге, где есть проблемы с использованием функции PHP mail().
onviser/mailer 适用场景与选型建议
onviser/mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 onviser/mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 onviser/mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-02-29