卫星技术 / 邮政
PHP库的Postal。
1.0.1
2023-01-27 12:57 UTC
Requires
- php: >=8.0
- rmccue/requests: ^2.0
Requires (Dev)
- phpstan/phpstan: ^1.9
README
这个库是由postalserver/postal-php分叉的,它帮助您通过PHP 8.0及以上版本的Postal发送电子邮件。
安装
使用Composer安装库
$ composer require atellitech/postal
使用方法
发送电子邮件非常简单。只需参考下面的示例。在开始之前,您需要登录到我们的Web界面并生成新的API凭证。
// Create a new message $message = new AtelliTech\Postal\SendMessage; // 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!'); // Create a new Postal client using the server key you generate in the web interface $client = new AtelliTech\Postal\Client('https://postal.yourdomain.com', 'your-api-key'); // Send the message and get the result $result = $message->send($client); // 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 }