EZMAIL is a lightweight package created with PHP using the official MIME documentation to send emails using the latest SMTP configuration. By using this package you will be able to send emails securely to anyone with a valid email address.
composer require ezmail/ezmail
<?php
use EZMAIL\EZMAIL; //update this according to your path.
use \Exceptions;
#Autoload
require 'vendor/autoload.php';
$ezmail = new EZMAIL();
#Config
$ezmail->appName = "EZMAIL";
$ezmail->hostName = "smtp.myhost.com";
$ezmail->portNumber = 123;
$ezmail->username = "myUsername";
$ezmail->password = "myPassword";
#Email
$ezmail->subject = "this is subject";
$ezmail->body = "this is message";
$ezmail->to = [ "Mr Recv" => "toEmail@example.com" ];
# or
$ezmail->to = [ "toEmail@example.com" ]; # name is optional for all address fields
#Optionally can be configured directly from the constructor on PHP 8+
#$ezmail = new EZMAIL(appName: "EZMAIL", hostName: "smtp.myhost.com", ...);
#uncomment to send email with attachments. A full file path or url is required.
//$ezmail->attachments = [ "My File.txt" => "https://mywebsite/myfile.txt" ];
// or
//$ezmail->attachments = [ "https://mywebsite/myfile.txt" ];
try
{
$mailId = $ezmail->send(); // Mail ID from the mail server here.
}
catch(Exception $ex)
{
print($ex->getMessage());
}
#New instance
$ezmail = new EZMAIL();
$ezmail->subject = "";
$ezmail->body = "";
$ezmail->to = [];
$ezmail->from = []; //optional
$ezmail->cc = []; //optional
$ezmail->bcc = []; //optional
$ezmail->replyTo = []; //optional
$ezmail->attachments = []; //optional
$ezmail->bounceAddress = ""; //optional
$ezmail->skipMessageIdValidation = true; //optional
#Connection.
$ezmail->appName = "EZMAIL";
$ezmail->hostName = "";
$ezmail->portNumber = 587;
$ezmail->username = "";
$ezmail->password = "";
$ezmail->timeout = 30; //optional
$ezmail->authType = SMTP::AUTH_TYPE_STANDARD; // or SMTP::AUTH_TYPE_PLAIN, SMTP::AUTH_TYPE_2AUTH
$ezmail->authToken = ""; //if using SMTP::AUTH_TYPE_2AUTH
$ezmail->isDebug = false; //true to enable SMTP logging
#send mail
$ezmail->send();
EZMAIL is MIT licensed.