Giter Site home page Giter Site logo

php-smtp's Introduction

PHP SMTP

An easy to use SMTP (Simple Mail Transfer Protocol) library which helps you to send emails.

Installation

composer require snipworks/php-smtp

Examples

Unsecured

<?php

use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 25);
$mail->setLogin('[email protected]', 'password');
$mail->addTo('[email protected]', 'Example Receiver');
$mail->setFrom('[email protected]', 'Example Sender');
$mail->setSubject('Example subject');
$mail->setHtmlMessage('<b>Example message</b>...');

if($mail->send()){
    echo 'Success!';
} else {
    echo 'An error occurred.';
}

Secured (TLS)

<?php

use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 587);
$mail->setProtocol(Email::TLS);
$mail->setLogin('[email protected]', 'password');
$mail->addTo('[email protected]', 'Example Receiver');
$mail->setFrom('[email protected]', 'Example Sender');
$mail->setSubject('Example subject');
$mail->setHtmlMessage('<b>Example message</b>...');

if($mail->send()){
    echo 'Success!';
} else {
    echo 'An error occurred.';
}

It's discouraged to hard-code the SMTP login credentials like in the examples above. It's recommended to put them inside another file and load it or set it to environment variable

<?php

// config.php

define('SMTP_PRIMARY_EMAIL', '[email protected]');
define('SMTP_PRIMARY_PASSWORD', 'my very secret password');
<?php

require_once('config.php');
// ...
$mail->setLogin(SMTP_PRIMARY_EMAIL, SMTP_PRIMARY_PASSWORD);
// ...

It's also recommended to put the config outside the public web root if possible. This for example prevents people from including your PHP file remotely by a misconfiguration.

php-smtp's People

Contributors

jaywilliams avatar schnabear avatar snipworks avatar sonkodmitry avatar yani avatar

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.