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 cakePHP’sCakeEmail. This class replaces the EmailComponent and gives more flexibility in sending emails. To know more about CakeEmail, please click here.

Step 1

Define the text and html templates in following files respectively:

app/View/Emails/html/welcome.ctp
app/View/Emails/text/welcome.ctp

Step 2

Define the text and html layouts in following files respectively:

app/View/Layouts/Emails/html/default.ctp
app/View/Layouts/Emails/text/default.ctp

Step 3

Create a file app/Config/email.php with the following content:

<?php
class EmailConfig {
public $smtp2go = array(
'host' => 'tls://mail.smtp2go.com',
'port' => 2525,
// 8025, 587 and 25 can also be used. Use Port 465 for SSL.

'username' => 'USERNAME',
'password' => 'PASSWORD',
'transport' => 'Smtp'
);
}
?>

Step 4

Add the following code in your controller:

<?php
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('smtp2go');
$email->from(array('sender@example.com' => 'Sender Name'));
$email->to(array('recipient@example.com' => 'Recipient Name'));
$email->subject('Your Subject');
$email->emailFormat('both');
// both = html + text.

$email->template('template');
if ($email->send()) {
echo "Message has been sent.";
} else {
echo $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.