Already registered? 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.
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.
Define the text and html templates in following files respectively:
app/views/elements/email/text/welcome.ctp
app/views/elements/email/html/welcome.ctp
Define the text and html layouts in following files respectively:
app/views/layouts/email/text/default.ctp
app/views/layouts/email/html/default.ctp
Add the email component as below in your controller:
<?php
var $components = array('Email');
?>
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;
}
?>
Try SMTP2GO free for as long as you like:
Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.