yidas / socket-mailer
使用fsockopen的PHP SMTP邮件发送库。
1.1.0
2023-10-05 10:02 UTC
This package is auto-updated.
Last update: 2024-09-05 12:04:39 UTC
README
使用套接字的PHP SMTP邮件发送库实现
演示
$mailer = new \yidas\socketMailer\Mailer([ 'host' => 'mail.your.com', 'username' => 'service@your.com', 'password' => 'passwd', ]); $result = $mailer ->setSubject('Mail Title') ->setBody('Content Text') ->setTo(['name@your.com', 'peter@your.com' => 'Peter']) ->setFrom(['service@your.com' => 'Service Mailer']) ->setCc(['cc@your.com' => 'CC Receiver']) ->setBcc(['bcc@your.com']) ->send();
需求
此库需要以下内容
- PHP 5.4.0+
安装
在你的项目中运行Composer
composer require yidas/socket-mailer
然后根据你的PHP框架在Composer加载后调用它
require __DIR__ . '/vendor/autoload.php'; use \yidas\socketMailer\Mailer;
配置
使用本地主机MTA
$mailer = new \yidas\socketMailer\Mailer()
配置外部MTA服务器
$mailer = new \yidas\socketMailer\Mailer([ 'host' => 'mail.your.com', 'username' => 'service@your.com', 'password' => 'passwd', 'port' => 587, 'encryption' => 'tls', ]);
SSL连接
$mailer = new \yidas\socketMailer\Mailer([ // ... 'port' => 465, 'encryption' => 'ssl', ]);
非认证连接
如果你想要在不允许的网络中连接到具有免费认证的SMTP中继服务器
$mailer = new \yidas\socketMailer\Mailer([ 'host' => 'mail.your.com', 'port' => 25, ]);
用法
debugOn()
public self debugOn()
setFrom()
public self setFrom(string|array $form)
setTo()
public self setTo(array $recipients)
setCc()
public self setCc(array $recipients)
setBcc()
public self setBcc(array $recipients)
setBody()
public self setBody(string $text)
setSubject()
public self setSubject(string $title)
addHeader()
public self addHeader($key, $value)
示例
$mailer = $mailer->addHeader('Your-Header-Name', 'the header value');
send()
public boolean send()