What is LSMailer?

LSMailer is a modern and efficient library to send emails using SMTP driver. It can be use in simple projects, where there is a need for a simple way to send emails (as in contact forms, polls, etc).

It has very intuitive methods, as to(), cc(), bcc(), send(). More than that, these methods are chainable, so you can always play in an elegant way with the parameters.

It works with simple, TLS or SSL SMTP accounts. Debugging option also available (just use the debug flag).


At least PHP 5.4.

Optionally, phpunit to run the test suite.


If you're using composer, then add this to your composer.json and run composer update.


Otherwise, in your code, include autoload.php file from this package:

require '<path>/<to>/<package>/vendor/autoload.php';

Before you start

You may need to update an internal value for sending host (identified by its fully qualified DNS host name - for example Open LSMailer/Drivers/LSSmtp.php in a text editor of your choice.

        $sending_host = 'localhost';

replace it by:

        $sending_host = '';


Example of static config

Configuration is pretty straightforward, you need to supply the server information and credentials in a stdClass structure. For example, before sending an email in your code you must have:


    $conf = new \stdClass;
    $conf->host = '';
    $conf->port = 465;
    $conf->secure = 'ssl';
    $conf->user = 'user';
    $conf->pass = 'secret';
    $conf->charset = 'ISO-8859-2';
    $conf->timezone = 'UTC+2';

Parameters explained:

  • host - hostname where the mailserver is located (e.g. localhost, If using ssl, don't prepend with ssl:// but use the secure flag (see below).
  • port - (default: 25) port on which the smtp service is running
  • secure - (default: none) ssl|tls -check your mailserver to see what's the preferred way
  • user - username (only if smtp requires authorization - most of the cases)
  • pass - password (only if smtp requires authorization - most of the cases)
  • charset - (default: UTF-8) character encoding for messages
  • timezone - (default: Europe/Amsterdam) - your timezone

From these parameters, only host, port are required, added to user and pass if authorization used.

Dynamic configuration

Available to be dynamically changes is the format() of the messages.

It can be html|text (default:text)


Also, for testing purposes, you can use debug()


Debug messages will be outputted to console. Defaults to 0.


After preparing the static configuration, you can use it like this:

    require 'vendor/autoload.php';

    use LSMailer\LSMail;

    $conf = new \stdClass;
    $conf->host = '';
    $conf->port = 465;
    $conf->secure = 'ssl';
    $conf->user = 'mytestuser';
    $conf->pass = 's93nfg2mss12';
    $conf->timezone = 'Europe/Dublin';

    $mailer = LSMail::factory('smtp', $conf);
    $mailer->format('html'); // dynamic configuration

        ->to(array('', '; John Doe'))
        ->to('; Another Joe')

        ->cc('; Jane')

    $mailer->subject("LSMailer - nice piece of software");

    $mailer->body("<strong>Text and roses.</strong>");
        ->attach(array('/path/file2', '/path/file3'));


All methods are chainable, and with names very intuitive (they correspond to the email fields, as To:, Cc:, ReplyTo:).