FAQ

Test emailers

You can use UpdateCase to setup emailers which come from the server
-> This allows to quickly setup responsive emails and test them before integrating into the software







# 1 > Controller

In the controller "PagesController" add the following method
-> If you do NOT have authentication change to function view($send = false)

public function user_view($send = false) {

if ($send) {

//$to = $this->getUserEmail();
$to = "test@undologic.com";
//pr ($to);exit;
$vars = array(
'send' => 'this to the view',
'another' => 'sending to the view'
);
$subject = 'Email template TEST';
$succes = $this->send($to, $vars, $subject, 'email_template');

if ($succes) {
$this->Session->setFlash('Email sent to your email address: '.$to);
} else {
$this->Session->setFlash('Problem sending email');
}
$this->redirect($this->referer());

} else {

}
$this->layout = false;
}




# 2 > Template

Create a file in 'View/Emails/html/email_template.ctp' with one line in it

<?= $this->Element('emailers/template_a'); ?>

 





# 3 > Create template

Create a file "View/Elements/emailers/template_a.ctp"

And in this file you will add all the responsive email content





# 4 > View

Create a view which will allow us to see before we send the email "View/Pages/user_view.ctp" with one line:

<?= $this->Element('emailers/template_a'); ?>




# 5 > AppController

Only if this does NOT exist create this function in the app_controller

public function send($to, $vars, $subject, $template = 'default') {


$Email = new CakeEmail();
$Email->viewVars(array(
'subject' => $subject,
'vars' => $vars,
'domain' => Router::url("/", TRUE)
));
$Email->config('smtp');

if (isset($vars['email'])) {
$Email->from($vars['email']);
}

$Email->to($to);

//$Email->bcc(array('test@undologic.com'));

$Email->subject($subject);
$Email->emailFormat('html');

$Email->template($template);
//pr ($Email);exit;
$sent = $Email->send();
//pr ($sent);exit;
if ($sent) {
return TRUE;
} else {
die ('could not email ');
return FALSE;
}
}




# 6 > Config

Open the config for the email settings "app/Config/email.php"
- This file is already created you just need to ensure the public $smtp is not commented

public $smtp = array(
'transport' => 'Smtp',
'from' => array('info@domain.com' => 'Name on email'),
'host' => 'servername.com',
'port' => 587,
'timeout' => 30,
'username' => 'email@domain.com',
'password' => 'pass2222k77kkk9999',
'client' => null,
//'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);

 





# 7 > Use

Now you can navigate in your browser to:

localhost/project/user/Pages/view

and this will display the email

then to send add a true to the end:

localhost/project/user/Pages/view/true

And an email will be sent to the address you specified in the controller