Git Product home page Git Product logo

mail's Introduction

Ceus Media Mail Library

Produce, send and read mails using PHP + IMAP & SMTP.

Latest Stable Version Total Downloads License PHPStan Enabled


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("[email protected]", "my_password")
	->send(\CeusMedia\Mail\Message::getInstance()
		->setSender("[email protected]", "John Doe")
		->addRecipient("[email protected]", "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("[email protected]", "John Doe");
$message->addRecipient("[email protected]", "Mike Foo");
$message->addRecipient("[email protected]", NULL, 'cc');
$message->addRecipient("[email protected]", 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("[email protected]");
$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("[email protected]", "John Doe")
	->to("[email protected]", "Mike Foo")
	->bcc("[email protected]")
	->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:

  1. Open a browser an log into Google using a Google account.
  2. Allow "less secure apps" to have access.
  3. Allow app to have access.
  4. Try again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.