For Developers By Developers

You can integrate Mailazy in minutes with your platform. Build and monitor your email solution on a trusted foundation with technical and strategic support when you need it the most.

Configure OTP emails with SMTP for CakePHP

OTP emails is an important component of any email communication strategy. In order to ensure delivery of OTP emails to your customers, reply on a trusted cloud-based email provider like Mailazy as a partner in your growth journey.

Prerequisites

You need to complete these given prerequisites, you can skip the step if you have already completed.

  1. Sign up for a Mailazy account.

  2. Complete Domain Authentication.

  3. Generate the Mailazy Access Key

Integrate Mailazy with CakePHP

CakePHP comes with an email library that supports SMTP. You can check CakePHP documentation page for more details. We have developed an example that shows how to send an email with both HTML and text bodies.

In app/views/layouts/ you need to define the layout of your text and HTML emails:

email/
html/
default.ctp
text/
default.ctp

In app/views/layouts/email/text/default.ctp add:

< ?php echo  $content_for_layout; ?>

and in app/views/layouts/email/html/default.ctp add:

< ?php echo  $content_for_layout; ?>

Then create the template for your emails.

In this example we created templates for a Login email with the following structure:

app/
views/
elements/
email/
text/
registration.ctp
html/
registration.ctp

In app/views/elements/email/text/registration.ctp add:

Dear < ?php echo $name ?>,

Thank you for Login. Please go to http://domain.com to finish your registration.

and in app/views/layouts/email/html/default.ctp add:

Dear < ?php echo $name ?>,

Thank you for registering. Please go to here to finish your registration.

In your controller enable the email component:

< ?php var $components = array('Email'); ?>

Then anywhere in your controller you can do something like the following to send an email: (make sure to replace your own access_key / access_secret details, better to make them constant)

$this->Email->smtpOptions  =  array(
  'port'=>'587',
  'timeout'=>'30',
  'host' => 'smtp.mailazy.com',
  'username'=>'access_key',
  'password'=>'access_secret'
);

$this->Email->delivery  = 'smtp';
$this->Email->from  = 'Your Name ';
$this->Email->to  = 'Recipient Name ';
$this->set('name', 'Recipient Name');
$this->Email->subject  = 'This is a subject';
$this->Email->template  = 'Login';
$this->Email->sendAs  = 'both';
$this->Email->send();

Send Emails with Mailazy

Mailazy is a simple email service to use, yet it provides so many benefits. Mailazy is the only simple transactional email service you’ll need. And the forever free plan lets you test drive it., Mailazy's team is well-equipped to help you quickly resolve your queries and issues. Try us for free today!

Signup for Free Developer Documentation

Ready to get started?

For High-Volume custom requirements send us an email and we will come up with a detailed quote within 24 hours.

Contact Us