SMTP客户端

0.9.0 2017-09-01 21:19 UTC

This package is auto-updated.

Last update: 2024-09-22 06:03:04 UTC


README

此客户端使用SMTP协议发送消息。这使得它能够

  • 从正常邮件功能不起作用的地方发送邮件;
  • 在一次调用中将消息发送给多个收件人。

基本使用示例

use gaswelder\smtp\Client;
use gaswelder\smtp\Mail;

$mail = new Mail();
$mail->subject = "Hey there";
$mail->body = ";)";

$returnPath = "bob@example.net";
$destinationPath = "alice@example.net";

$smtp = new Client();
$smtp->connect("smtp.example.net");
$smtp->login("bob", "****");
$smtp->send($mail, $returnPath, $destinationPath);

邮件列表示例

use gaswelder\smtp\Client;
use gaswelder\smtp\Mail;

$mail = new Mail();
$mail->to = "To whom it might concern";
$mail->subject = "Viagra!";
$mail->body = ";)";

$recipients = [
	"phb@fortune.com",
	"bob@example.net",
	"bill@example.net"
];
$smtp = new Client();
$smtp->connect("mail.net");
$smtp->login("mailer", "****");
$smtp->send($mail, "mailer@mail.net", $recipients);

SSL

客户端始终在登录前使用SSL(STARTTLS)。可以通过将ssl选项定义为SSL上下文选项映射来调整SSL参数,具体请参阅https://php.ac.cn/manual/en/context.ssl.php。例如,为了允许自签名证书

$client = new Client([
	'ssl' => [
		'allow_self_signed' => true
	]
]);

日志记录

要获取日志消息(包括客户端和服务器通过连接发送的消息),请将logger选项定义为接受日志行的可调用函数

$client = new Client([
	'logger' => function($line) {
		fwrite(STDERR, $line."\n");
	}
]);

安装

composer require gaswelder/smtp