simpraight / lwmail
轻量级邮件库
v0.1
2014-03-12 16:08 UTC
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-09-28 15:35:06 UTC
README
轻量级邮件
目前为测试版。
这个库用于在PHP中轻松进行电子邮件传输。当前支持的协议如下。
- POP3 (+SSL)
- SMTP (+SSL,TLS 和 STARTTLS)
- SMTP-AUTH (PLAIN, LOGIN, CRAM-MD5)
它适用于日本环境中的简单和轻量级使用。
安装
请将其附加到 composer.json 中。
require: {
"simpraight/lwmail": "*"
}
然后运行命令 composer.phar install
或 composer.phar update
接下来,描述以下文件。
<?php
require 'vendor/autoload.php';
用法
###POP3 示例代码
<?php
use \LWMail\Protocol\POP3;
use \LWMail\MailMessage;
$pop3 = new POP3(array(
'protocol' => 'ssl',
'host' => 'smtp.gmail.com',
'port' => 995,
'pop3.user' => 'xxxxxxx',
'pop3.pass' => 'xxxxxxx',
));
$mails = array();
foreach ($pop3->getList() as $msg)
{
$mails[] = MailMessage::parse($pop3->getRetr($msg['id']));
}
###SMTP 示例代码
use \LWMail\Protocol\SMTP;
use \LWMail\MailMessage;
$message = MailMessage::create();
$message->from = 'Myname <me@sample.com>'; // or array('name' => 'Myname', 'mail' => 'me@sample.com');
$message->to = 'Yourname <you@sample,com>';
$message->cc = 'someone1@sample.com';
$message->cc = 'someone2@sample.com'; // Add to CC, not overwrite.
$message->subject = "Mail Subject";
$message->body = "Message \n Body";
$message->attachment = array('filename' => 'test1.pdf', 'path' => '/tmp/test1.pdf', 'mime' => 'application/pdf');
$message->attachment = array('filename' => 'test2.pdf', 'path' => '/tmp/test2.pdf', 'mime' => 'application/pdf'); // Add attachment.
$smtp = new SMTP(array(
'host' => 'smtp.gmail.com',
'port' => 587,
'smtp.auth' => true,
'smtp.user' => 'xxxxxx',
'smtp.pass' => 'xxxxxx',
'smtp.starttls' => true,
));
$smtp->send($message);
许可证
MIT 许可证