PHP code example of sun / sunmailer

1. Go to this page and download the library: Download sun/sunmailer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sun / sunmailer example snippets


  

// namespace
use SunMailer\Mailer;
use SunMailer\View;
use SunMailer\MailerException;


$email      =   '[email protected]';
$name       =   'Test mail name';
$subject    =   'Test mail subject';
$body       =   'Test mail body';
  
  
try
{
    if(Mailer::send($email, $name, $subject, $body))
    {
        echo 'Email has been sent successfully.';
    }
}
catch (MailerException $e)
{
    echo  'Oops!!! Something goes to wrong. '. $e->getMessage();
}

$attached   =   'images/sunmailer.jpg';
 
if(Mailer::send($email, $name, $subject, $body, $attached))
{
    echo 'Email has been sent successfully.';
}
 

View::render('to.path.test');

$body = View::render('email.test');
 
if(Mailer::send($email, $name, $subject, $body))
{
    echo 'Email has been sent successfully.';
}

$data  = [ 'name'  =>  'Test Name' ];
View::render('email.test', $data);

@name

Mailer::logClean();

// to get configuration file
Helper::config();

// to get root directory path
Helper::root_path();

// to get log directory path
Helper::log_path();

// to get temp directory path
Helper::temp_path();