- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Seme Email Library
The Seme_Email
library purpose is for sending email from Seme Framework. Seme Email has HTML email template for dynamic content of html.
Class Structure
Here is the Structure of Seme Email Class.
<?php
Class Seme_Email {
public $log;
public function __construct() {}
public function from($from_email_address[, $name='']): Seme_Email {}
public function to($to_email_address[, $name='']): Seme_Email {}
public function subject($title_or_subject_email): Seme_Email {}
public function text($ascii_text): Seme_Email {}
public function html($html_content): Seme_Email {}
public function send(): Seme_Email {}
public function template($file_template_php): Seme_Email {}
public function replacer($array_of_string): Seme_Email {}
public function attachment_add($filepath[, $filename='']): Seme_Email {}
public function attachment_clear(): Seme_Email {}
public function getLog(): string {}
public function preview(): void {}
}
Basic Usage
You can put libary loader in constructor of controller or on each method in your controller.
To use the Seme Email library, you can add a few lines of code to a controller in the Seme Framework.
The following is a basic example of implementing the Seme Email code in a Controller.
Please create a new file under app/controller
named it emailregister.php
, then copy paste this HTML code below into that file.
<?php
Class EmailRegister extends \SENE_Controller{
public function __construct(){
parent::__construct();
$this->lib('seme_email');
}
public function index(){
$this->seme_email->flush();
$this->seme_email->replyto('Support Example Website', 'support@cenah.co.id');
$this->seme_email->from('noreply@example.com', 'Adry from Example Website');
$this->seme_email->subject('Registration Successful');
$this->seme_email->to('agus.setiawan@example.com', 'Agus Setiawan');
$this->seme_email->text('Thank you for registering on Example website.');
$this->seme_email->send();
// optional, verbose the process
dd($this->seme_email->getLog());
}
}
To run the process of sending email, you can simply call this class via the browser. Example: http://localhost/seme_framework/emailregister.
From Method
This method mandatory for declare origin of email. Required two parameter, first parameter is email and the second parameter is name of sender.
Subject Method
This method mandatory for declare title of email. Required one parameter contained about your summary.
To Method
This method mandatory for declare target of email. Required two parameter, first parameter is email and the second parameter is name of sender. Can be called more than once for sending multiple email address.
Template Method
This method only required if you one to create html formatted email. Default location about this file is in kero/lib/seme_email/template
.
You can replace the string by using replacer method for creating dynamic email. Here is the example of HTML email template:
<html>
<body>
<p>Hi {{full_name}},</p>
<p>Thank you for using registering at {{site_name}}.</p>
<p>You can clicking on this link {{dashboard_link}} to go to your dashboard.</p>
</body>
</html>
On HTML script above, we can see the code. You can replace this string with real name through the script.
Replacer Method
This method allow replacing string on email template with coding. Here is the example:
<?php
Class EmailRegister extends \SENE_Controller{
public function __construct(){
parent::__construct();
$this->lib('seme_email');
}
public function index(){
$replacer = array();
$replacer['site_name'] = 'Example Website';
$replacer['full_name'] = 'Agus Setiawan';
$replacer['dashboard_link'] = base_url('dashboard/');
$this->seme_email->flush();
$this->seme_email->replyto('Support Example Website', 'support@cenah.co.id');
$this->seme_email->from('noreply@example.com', 'Adry from Example Website');
$this->seme_email->subject('Registration Successful');
$this->seme_email->to('agus.setiawan@example.com', 'Agus Setiawan');
$this->seme_email->template('account_register');
$this->seme_email->replacer($replacer);
$this->seme_email->send();
// optional, verbose the process
dd($this->seme_email->getLog());
}
}
If this example combined with email template above, you can send email with replaced by Agus Setiawan.
Flush method
Use this method for clearing assigned properties used before.
Special Notes
Please makes more attention if you want to send email by following community guidance for email usage. If your email always sent to spam, you have to use real domain and real working email.
Google has completed guide for email usage. Here is the quick explanation:
- Always put Subject on email.
- Body or main content email consist of greetings, main content, and footer.
- Avoid attachment.
- For default purpose always use noreply@example.com, adjust example.com to your domain.
- For money related email content use finance@example.com and makes sure the email is active.
- For marketing purpose please use real name of marketing such as adry@example.com and makes sure the email is active can be replied.