Log In

This guide helps to setup your SMTP2GO server as Outgoing SMTP Server in cakePHP Framework.

This guide provides a simple script to send an email with both html and text bodies using EmailComponent. To know more about EmailComponent, please click here.

Step 1

Please change the following variables in this guide:

Sender Name: the sender’s name.

sender@example.com: the sender’s email address.

Recipient Name: the recipient’s name.

recipient@example.com: the recipient’s email address.

USERNAME: your SMTP username.

PASSWORD: your SMTP password.

welcome.ctp: the file name of your template.

Step 2

Define the text and html templates in following files respectively:

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

Step 3

Define the text and html layouts in following files respectively:

app/views/layouts/email/text/default.ctp
app/views/layouts/email/html/default.ctp

Step 4

Add the email component as below in your controller:

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

Step 5

Add the following code in your controller:

<?php
$this->Email->to = 'Recipient Name';
$this->Email->subject = 'Your Subject';
$this->Email->from = 'Sender Name';
$this->Email->sendAs = 'both'; // both = html + text.
$this->Email->template = 'welcome';
$this->Email->smtpOptions = array(
'port'=>'2525', // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
'timeout'=>'30',
'host' => 'tls://mail.smtp2go.com',
'username'=>'USERNAME',
'password'=>'PASSWORD',
);
$this->Email->delivery = 'smtp';
if ($this->Email->send()) {
echo 'Message has been sent.';
} else {
echo $this->Email->smtpError;
}
?>

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.