initphp/mailer

InitPHP 邮件库

1.1 2023-07-20 04:25 UTC

This package is auto-updated.

Last update: 2024-09-20 07:05:00 UTC


README

这是一个简单的SMTP邮件发送库,由一个类组成。

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

安装

composer require initphp/mailer

要求

  • PHP 7.4 或更高版本
  • MBString 扩展
  • Iconv 扩展
  • FileInfo 扩展

用法

$config = [
    'mailType'  => 'text' // or 'html'
    'protocol'  => 'smtp' // or 'mail' or 'sendmail'
    'SMTPAuth'  => true,
    'SMTPHost'  => 'smtp.gmail.com',
    'SMTPUser'  => 'your-mail@gmail.com',
    'SMTPPass'  => 'YourMailPassword',
    'SMTPPort'  => 587
];
$mailer = \InitPHP\Mailer\Mailer::newInstance($config);

$mailer->setFrom('info@muhammetsafak.com.tr', 'Muhammet Şafak');
//$mailer->setTo('example@example.com');
//$mailer->setCC('john@hotmail.com');
//$mailer->setBCC('testing@gmail.com');
$mailer->setSubject('Mail Subject');
$mailer->setMessage('Mail Body Message');
$mailer->send();

方法

newInstance()

创建一个新的邮件对象并返回它。

public static function newInstance(?array $config = null): \InitPHP\Mailer\Mailer

clear()

public function clear(bool $clearAttachments = false): self

setHeader()

public function setHeader(string $header, string $value): self

setFrom()

public function setFrom(string $from, string $name = '', ?string $returnPath = null): self

setReplyTo()

public function setReplyTo(string $replyTo, string $name = ''): self

setTo()

public function setTo(string|array $to): self

setCC()

public function setCC(string $cc): self

setBCC()

public function setBCC(string $bcc, ?int $limit = null): self

setSubject()

public function setSubject(string $subject): self

setMessage()

public function setMessage(string $body): self

setAttachmentCID()

public function setAttachmentCID(string $fileName): false|string

setAltMessage()

public function setAltMessage(string $str): self

setMailType()

public function setMailType(string $type = 'text'): self
  • $type : texthtml

setWordWrap()

public function setWordWrap(bool $wordWrap = true): self

setProtocol()

public function setProtocol(string $protocol = 'mail'): self
  • $protocol : mail, sendmailsmtp

setPriority()

public function setPriority(int $n = 3): self
  • $n : 从 1 到 5 的整数。

setNewline()

public function setNewline(string $newLine = \PHP_EOL): self

setCRLF()

public function setCRLF(string $CRLF = \PHP_EOL): self

attach()

public function attach(string|resource $file, string $disposition = '', ?string $newName = null, ?string $mime = null): false|self

send()

public function send(bool $autoClear = true): bool

printDebugger()

public function printDebugger(array $include = ['headers', 'subject', 'body']): string

获取帮助

如果您有任何问题、疑虑、错误报告等,请在存储库的问题跟踪器中提交问题。

参与贡献

所有对本项目的贡献都将根据 MIT 许可证发布。通过提交拉取请求或提交错误、问题或功能请求,您同意遵守本版权放弃声明。

帮助的主要方式有两种

  • 使用问题跟踪器,
  • 更改代码库。

使用问题跟踪器

使用问题跟踪器提出功能请求、报告错误和提问。这也是与项目开发者以及对此解决方案感兴趣的其他人建立联系的好方法。

使用问题跟踪器找到贡献的方式。找到一个错误或功能,在问题中说明您将承担这项工作,然后遵循下面更改代码库的指南。

更改代码库

一般来说,您应该在此存储库上进行分支,在自己的分支中进行更改,然后提交拉取请求。所有新代码都应具有关联的单元测试,以验证实现的功能和缺陷的存在或不存在。此外,代码应遵循项目规定的任何样式和架构指南。如果没有此类指南,模仿现有代码库中的样式和模式。

致谢

许可证

版权所有 © 2022 MIT 许可证