Git Product home page Git Product logo

mailer's Introduction

Basic Usage:

1. Customize the congfiguration setting in /config/mailer.php
	<?php
	return array
	(
		'production' => array(
			'transport'	=> 'smtp',
			'options'	=> array
							(
								'hostname'	=> 'smtp.mail.com',
								'username'	=> '[email protected]',
								'password'	=> 'password',
								'encryption'=> 'ssl',
								'port'		=> '465',
							),
		),
		'development' => array(
			'transport'	=> 'smtp'
		)
	);


2. Create a class that extends the Mailer class and save it to /classes/mailer/class_name.php (Minus the Mailer_)
	<?php defined('SYSPATH') or die('No direct script access.');

	class Mailer_User extends Mailer {

		public function before()
		{
			// To set the config by environment
			$this->config		= Kohana::$environment;
		}

		public function welcome($args) 
		{
			$this->to 			= array('[email protected]' => 'Tom');
			$this->bcc			= array('[email protected]' => 'Admin');
			$this->from 		= array('[email protected]' => 'The Team');
			$this->subject		= 'Welcome!';
			$this->attachments	= array('/path/to/file/file.txt', '/path/to/file/file2.txt');
			$this->data 		= $args;
		}

	}


3. Create the view for the email and save it to /views/mailer/class_name/method_name.php (Minus the Mailer_)
	<p>Welcome <?= $user['name']; ?>,</p>
	<p>We are glad you signed up for our web app.  Hope you enjoy.</p>
	<p>The Team</p>



4. Use the Mailer_User class in one of your controllers

	public function action_submit() 
	{
		$data = array(
			'user' => array(
				'name' => 'Tom'
			)
		);

		Mailer::factory('user')->send_welcome();
		
		//you can also pass arguments to the mailer
		Mailer::factory('user')->send_welcome($data);
		
		//you can also use instance
		Mailer::instance('user')->send_welcome($data);
		
		//you can also pass arguments in factory
		Mailer::factory('user', 'welcome', $data);
		
		//you can also send direct from the controller
		Mailer::instance()
			->to('[email protected]')
			->from('[email protected]')
			->subject('Welcome!')
			->html('Welcome!')
			->send();
	}

mailer's People

Contributors

kanema avatar themusicman avatar jmhobbs avatar daniloassis avatar ryross avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.