iamgold / postal
PHP 库的 Postal。
v1.0.0
2023-01-27 07:16 UTC
Requires
- php: >=8.0
- rmccue/requests: ^2.0
This package is auto-updated.
Last update: 2024-09-27 10:45:32 UTC
README
这个库是从 postalserver/postal-php 分支出来的,它可以帮助你在 PHP 8.0 及以上版本中使用 Postal 发送电子邮件。Postal
安装
使用 Composer 安装库
$ composer require iamgold/postal
用法
发送电子邮件非常简单。只需按照下面的示例进行操作。在开始之前,您需要登录到我们的网页界面并生成一个新的 API 凭证。
// Create a new Postal client using the server key you generate in the web interface $client = new Postal\Client('https://postal.yourdomain.com', 'your-api-key'); // Create a new message $message = new Postal\SendMessage($client); // Add some recipients $message->to('john@example.com'); $message->to('mary@example.com'); $message->cc('mike@example.com'); $message->bcc('secret@awesomeapp.com'); // Specify who the message should be from. This must be from a verified domain // on your mail server. $message->from('test@test.postal.io'); // Set the subject $message->subject('Hi there!'); // Set the content for the e-mail $message->plainBody('Hello world!'); $message->htmlBody('<p>Hello world!</p>'); // Add any custom headers $message->header('X-PHP-Test', 'value'); // Attach any files $message->attach('textmessage.txt', 'text/plain', 'Hello world!'); // Send the message and get the result $result = $message->send(); // Loop through each of the recipients to get the message ID foreach ($result->recipients() as $email => $message) { $email; // The e-mail address of the recipient $message->id(); // Returns the message ID $message->token(); // Returns the message's token }