xp-framework / mail
为 XP 的邮件功能
v9.0.3
2022-02-27 10:14 UTC
Requires
- php: >=7.0.0
- xp-framework/core: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
- xp-framework/logging: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
- xp-framework/networking: ^10.0 | ^9.0 | ^8.0 | ^7.0
- xp-framework/text-encode: ^10.0 | ^9.0 | ^8.0 | ^7.0
Requires (Dev)
- xp-framework/unittest: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
README
支持电子邮件 API、POP3、IMAP、MailDir、SMTP。
创建电子邮件
use peer\mail\{Message, InternetAddress}; $msg= new Message(); $msg->setFrom(new InternetAddress('friebe@example.com', 'Timm Friebe')); $msg->addRecipient(TO, new InternetAddress('foo@bar.baz', 'Foo Bar')); $msg->addRecipient(CC, new InternetAddress('timm@foo.bar', 'Timm Friebe')); $msg->setHeader('X-Binford', '6100 (more power)'); $msg->setSubject('Hello world'); $msg->setBody('Testmail');
发送电子邮件
use peer\mail\transport\{MailTransport, TransportException}; $smtp= new MailTransport(); try { $smtp->connect(); $smtp->send($msg); } catch (TransportException $e) { $e->printStackTrace(); } $smtp->close();
使用 SMTP 服务器
use peer\mail\transport\{SmtpConnection, TransportException}; $smtp= new SmtpConnection('esmtp://user:pass@mail.example.com:25/?auth=login'); try { $smtp->connect(); $smtp->send($msg); } catch (TransportException $e) { $e->printStackTrace(); } $smtp->close();