PHP code example of janisto / yii-mailer

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

    

janisto / yii-mailer example snippets


{
	"name": "app-name",
	"description": "App description",
	"type": "project",
	"prefer-stable": true,
	"

// Composer autoload
$composerAutoload = dirname(__FILE__) . '/../vendor/autoload.php';

	'aliases'=>array(
		'vendor' => realpath(__DIR__ . '/../../vendor'),
	),
	'components' => array(
		...
		'mailer' => array(
			'class' => 'vendor.janisto.yii-mailer.SwiftMailerComponent',
			'type' => 'smtp',
			'host' => 'email-smtp.us-east-1.amazonaws.com',
			'port' => 587,
			'username' => 'xxx',
			'password' => 'yyy',
			'security' => 'tls',
			'throttle' => 5*60,
		),
		...
	),

$message = Yii::app()->mailer
	->createMessage('Your subject', 'Here is the message itself')
	->setFrom(array('[email protected]' => 'From Name'))
	->setTo(array('[email protected]' => 'To Name'));

Yii::app()->mailer->send($message);

$failures = array();
$sent = 0;
$from = array('[email protected]' => 'From Name');
$emails = array(
	array('[email protected]' => 'To Name'),
	array('[email protected]' => 'To Name'),
	array('[email protected]' => 'To Name'),
);

/* @var Swift_Message $message */
$message = Yii::app()->mailer
	->createMessage('Your subject')
	->setFrom($from)
	->setBody('Here is the message itself')
	->addPart('<q>Here is the message itself</q>', 'text/html');

foreach ($emails as $to) {
	$message->setTo($to);
	try {
		$sent += Yii::app()->mailer->send($message, $failures);
	} catch (Exception $e) {
		// SMTP server not responding or limit exceeded?
		echo $e->getMessage();
	}
}

echo "$sent emails sent.\n";
echo "Failures:\n";
print_r($failures);