EasyMail a PHP Class

Credits

This class is an extension of PHPMailer

Class Features

EasyMail Class offers a quicker way of mailing for those who need to work quickly, or is a perfect mail platform for beginner developers who struggle with the usage of PHPMailer

How to use

Standard PHP Mail


require 'lib/EasyMail.php';
$mail = new EasyMail("PHP");

/*
 *  easySetup takes 3 params
 * 1. From Email
 * 2. From Name
 * 3. HTML Email true or false
 *
*/
$mail->easySetup('[email protected]', 'From Name', true);

/*
 * easyMail takes 4 params
 * 1. To Email
 * 2. Subject
 * 3. Message
 * 4. Attachment Paths (array)
 *
*/
$mail->easyMail('[email protected]', 'Subject', 'This is the email contents', array());
/*
 * EasySendStatus takes 0 params
 * It will return if the message has sent as true or false
 *
*/
if($mail->EasySendStatus() !== false){
    //Message has Sent
}
else{
    //Message has not sent
}

SMTP Mail


require 'lib/EasyMail.php';
$mail = new EasyMail("SMTP");
/*
*  setSMTP requires 5 params
*  1. SMTP_HOST
*  2. SMTP_LOGIN
*  3. SMTP_PWD
*  4. SMTP_PORT //Default is 587
*  5. SMTP_ENCRYPT // Default is TLS
*
*/
    $mail->setSMTP('', '', '', 'DEFAULT', 'DEFAULT');

/*
 *  easySetup takes 3 params
 * 1. From Email
 * 2. From Name
 * 3. HTML Email true or false
 *
*/
$mail->easySetup('[email protected]', 'From Name', true);

/*
 * easyMail takes 4 params
 * 1. To Email
 * 2. Subject
 * 3. Message
 * 4. Attachment Paths (array)
 *
*/
$mail->easyMail('[email protected]', 'Subject', 'This is the email contents', array());

/*
 * EasySendStatus takes 0 params
 * It will return if the message has sent as true or false
 *
*/
if($mail->EasySendStatus() !== false){
    //Message has Sent
}
else{
    //Message has not sent
}

Optional Extra

/*
 * easyMailCC takes 2 params
 * CC Email and BCC email
 * to leave one option empty do as so
 $mail->easyMailCC('[email protected]', '');
 OR
 $mail->easyMailCC('', '[email protected]');
 *
*/
    $mail->easyMailCC('[email protected]', '[email protected]');

HTML Email example

$mailBody = <<<EOD
<html>
<body>
    <h2 style="colour:blue;">My Email body</h2>
</body>
</html>
EOD;
//EODS must never have space on inside of tags

$mail->easyMail('[email protected]', 'Subject', $mailBody, array());