交接 / pop-mail
Pop PHP 框架的 Pop Mail 组件。PHP 版本 5.3 的补丁
0.1.0
2016-09-06 04:35 UTC
This package is auto-updated.
Last update: 2024-09-24 04:25:16 UTC
README
概述
pop-mail
是一个用于管理和发送电子邮件消息的组件。它具有完整的特性集,支持
- 发送到多个电子邮件
- 作为群组发送
- 管理头信息
- 附加文件
- 发送多个 MIME 类型(例如,文本、HTML 等)
- 保存稍后发送的电子邮件
pop-mail
是 Pop PHP 框架 的一个组件。
安装
使用 Composer 安装 pop-mail
。
composer require popphp/pop-mail
基本用法
发送基本电子邮件
use Pop\Mail\Mail; $mail = new Mail('Test Email Subject'); $mail->to('test@test.com'); $mail->cc('cc@test.com'); $mail->from('somebody@test.com'); $mail->setText('Hello World! This is a test email.'); $mail->send();
To: test@test.com
Subject: Test Email Subject
Cc: cc@test.com
From: somebody@test.com
Reply-To: somebody@test.com
Content-Type: text/plain; charset=utf-8
Hello World! This is a test email.
附加文件
use Pop\Mail\Mail; $mail = new Mail('Attaching a File'); $mail->to('test@test.com'); $mail->from('somebody@test.com'); $mail->setText('Check out this file.'); $mail->attachFile('lorem.docx'); $mail->send();
To: test@test.com
Subject: Attaching a File
From: somebody@test.com
Reply-To: somebody@test.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="7dbf357ee8df3d00a00cda688da71a8523f8123c"
This is a multi-part message in MIME format.
--7dbf357ee8df3d00a00cda688da71a8523f8123c
Content-Type: file; name="lorem.docx"
Content-Transfer-Encoding: base64
Content-Description: lorem.docx
Content-Disposition: attachment; filename="lorem.docx"
UEsDBBQACAgIAKmB9UYAAAAAAAAAAAAAAAALAAAAX3JlbHMvLnJlbHOtkk1LA0EMhu/9FUPu3Wwr
iMjO9iJCbyL1B4SZ7O7Qzgczaa3/3kEKulCKoMe8efPwHNJtzv6gTpyLi0HDqmlBcTDRujBqeNs9
[ ... Big long block of base 64 encoded data ... ]
L2NvcmUueG1sUEsBAhQAFAAICAgAqYH1RhkaEIMtAQAAXgQAABMAAAAAAAAAAAAAAAAAcRAAAFtD
b250ZW50X1R5cGVzXS54bWxQSwUGAAAAAAkACQA8AgAA3xEAAAAA
--7dbf357ee8df3d00a00cda688da71a8523f8123c
Content-type: text/plain; charset=utf-8
Check out this file.
--7dbf357ee8df3d00a00cda688da71a8523f8123c--
发送基于 HTML 和文本的电子邮件
$mail = new Mail('Sending an HTML Email'); $mail->to('test@test.com'); $mail->from('somebody@test.com'); $html = <<<HTML <html> <head> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> <p>This is a cool HTML email, huh?</p> </body> </html> HTML; $mail->setHtml($html); $mail->setText( 'This is the text message in case your email client cannot display HTML.' ); $mail->send();
To: test@test.com
Subject: Sending an HTML Email
From: somebody@test.com
Reply-To: somebody@test.com
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="d08ae99249fe6d0a03a8436ce3bea4ceffd208cb"
This is a multi-part message in MIME format.
--d08ae99249fe6d0a03a8436ce3bea4ceffd208cb
Content-type: text/plain; charset=utf-8
This is the text message in case your email client cannot display HTML.
--d08ae99249fe6d0a03a8436ce3bea4ceffd208cb
Content-type: text/html; charset=utf-8
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a cool HTML email, huh?</p>
</body>
</html>
--d08ae99249fe6d0a03a8436ce3bea4ceffd208cb--
保存稍后发送的电子邮件
use Pop\Mail\Mail; $mail = new Mail('Test Email Subject'); $mail->to('test@test.com'); $mail->cc('cc@test.com'); $mail->from('somebody@test.com'); $mail->setText('Hello World! This is a test email.'); $mail->saveTo(__DIR__ . '/email-queue');
这将在文件夹中写入电子邮件或电子邮件。然后,当您准备好发送它们时,您可以简单地这样做
use Pop\Mail\Mail; $mail = new Mail(); $mail->sendFrom(__DIR__ . '/email-queue', true);
true
参数是在发送后从文件夹中删除电子邮件的标志。