ceus-media / mail
Installs: 2 638
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-dom: *
- ext-fileinfo: *
- ext-iconv: *
- ext-imap: *
- ext-json: *
- ceus-media/cache: ^0.6 | 0.6.x-dev
- ceus-media/common: ^1.0 | 1.0.x-dev
- ezyang/htmlpurifier: dev-master
Requires (Dev)
- brianium/paratest: *
- ceus-media/bootstrap: ^0.6 | 0.6.x-dev
- ceus-media/doc-creator: ^1.0 | 1.0.x-dev
- ceus-media/phan-viewer: * | dev-master
- phan/phan: ^v5
- php-parallel-lint/php-parallel-lint: ^1.3 | dev-master
- phpstan/phpstan: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^9.5 | ^10.1
- rector/rector: *
- squizlabs/php_codesniffer: *
This package is auto-updated.
Last update: 2024-11-04 01:05:25 UTC
README
Produce, send and read mails using PHP + IMAP & SMTP.
Features
- Programming
- simple, easy, clean
- PHP 7.3+, object oriented style, chainable
- automatic encoding
- automatic MIME type detection
- MIME Contents
- HTML
- plain text
- file attachments
- inline images
- Partipicants
- To, Cc, Bcc
- sender and receiver names
- Transports
- SMTP, with TLS support
- local PHP mail function
- Mailbox
- access via IMAP and POP3
- search with criteria
- Checks
- address validity
- receiver reachability
Code Examples
Short version
This example shows how to send a text mail using chainability.
\CeusMedia\Mail\Transport\SMTP::getInstance("example.com", 587) ->setAuth("john@example.com", "my_password") ->send(\CeusMedia\Mail\Message::getInstance() ->setSender("john@example.com", "John Doe") ->addRecipient("mike@example.com", "Mike Foo") ->setSubject("This is just a test") ->addText("Test Message...") );
Long version
use \CeusMedia\Mail\Message; use \CeusMedia\Mail\Transport\SMTP; $message = new Message(); $message->setSender("john@example.com", "John Doe"); $message->addRecipient("mike@example.com", "Mike Foo"); $message->addRecipient("log@example.com", NULL, 'cc'); $message->addRecipient("spy@example.com", NULL, 'bcc' ); $message->setSubject("This is just a test"); $message->addText("Test Message..."); $message->addHTML('<h2><img src="CID:logo"/><br>Test Message</h2>'); $message->addInlineImage("logo", "logo.png"); $message->addFile("readme.md"); $transport = new SMTP("example.com", 587); $transport->setUsername("john@example.com"); $transport->setPassword("my_password"); $transport->setVerbose(TRUE); $transport->send( $message );
Future plans
- documentation for already existing parser
- automatic virus scan
- support for logging
- factories and other design patterns
- slim API - see "Future version"
Future version
Sending a mail should be as easy as possible. This is an outlook how the interface could look like in future.
Attention: This is pseudo code. The used classes are not implemented yet.
use \CeusMedia\Mail\Client; Client::getInstance("This is just a test") ->from("john@example.com", "John Doe") ->to("mike@example.com", "Mike Foo") ->bcc("spy@example.com") ->text("Test Message...") ->auth("my_password") ->port(587), ->error("handleMailException") ->send(); function handleMailException( $e ){ // ... }
Thoughts on this example
- Sending mail with this short code will be using SMTP, only.
- The SMTP server will be determined by fetching MX records of the user's domain.
- Setting the SMTP server port is still needed.
- Assigned receivers will be checked for existance automatically.
- If the auth method is receiving only one parameter, it will be understood as password.
- The auth username will be taken from sender address.
- Thrown exceptions can be catched by a defined error handler.
- If everything is set the mail can be sent.
Good to know
Using Google as SMTP
Google tried to protect its SMTP access by several measures. If you are having problems sending mails using Google SMTP, tried these steps:
- Open a browser an log into Google using a Google account.
- Allow "less secure apps" to have access.
- Allow app to have access.
- Try again!