PHP code example of gelembjuk / mail

1. Go to this page and download the library: Download gelembjuk/mail 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/ */

    

gelembjuk / mail example snippets



$formatteroptions = array( 
	'locale' => '', 
		// optional, add if you need international support
	'deflocale' => 'en', 
		// default locale. Optional as well, template from it are used if no in a `locale`
	'templateprocessorclass' => null, 
		// if not provided then smarty is used. this is one of classes from Gelembjuk/Templating
	'templatecompiledir' => $thisdir.'/email_tmp/',  
		// directory used to store tempopary files of cache engine . It i reuired for Smarty but not needed for Twig
	'templatespath' => $thisdir.'/email_templates/'
		// a base path where email templates and files with subjects are stored
	);
	
$maileroptions = array(
	'logger' => $logger,
		// (optional) Logger, instance of Gelembjuk\Logger\FileLogger, 
	'format' => $formatteroptions,
		// formatter options
	// other options related to specified email sending class
	// next options are only for PHPMailer
	'mailsystem' => 'smtp', // for phpmailer it can be smtp or mail
	'smtp_host' => 'smtp_host', 	// aka smtp.gmail.com
	'smtp_port' => 25,		// aka 587
	'smtp_secure' => false,		// or true in case of ssl/tls
	'smtp_auth' => true,		// usually true
	'smtp_user' => 'smtp user',	// aka your gmail account
	'smtp_password' => 'smtp password', // your smtp password (gmail etc)
);



$mailer = new \Gelembjuk\Mail\PHPMailer();

// OR
// $mailer = new \Gelembjuk\Mail\PHPNative(); // uses mail()
// OR 
// $mailer = new \Gelembjuk\Mail\NullMail(); // is only for testing, doesn't send only log

$mailer->initMailer($maileroptions);

$email_data = array(
	'user' => 'John Smith',
	'activationlink' => 'http://our_site.com/activateaccount/code'
);

$mailer->formatAndSendEmail(
	'activate',  // template name
	$email_data,
	'[email protected]', // send to email
	'[email protected]'  // send from email
	);



// send email with german template
$mailer->setFormatterOption('locale','de');

$mailer->formatAndSendEmail(
	'activate',  // template name
	$email_data,
	'[email protected]', // send to email
	'[email protected]'  // send from email
	);
	
// send same email with french template
$mailer->setFormatterOption('locale','fr');

$mailer->formatAndSendEmail(
	'activate',  // template name
	$email_data,
	'[email protected]', // send to email
	'[email protected]'  // send from email
	);