Tejas Rana
  • _home
  • _blogs
  • _services
  • _contact-me
Tejas Rana
About.Blogs.Services.Contact.
  • LinkedIn
  • Instagram
  • Facebook

© 2026 — CopyrightAll Rights reserved

Contact Us
[email protected]+91 9530107998
← Back to all blogs

How to send email in Cakephp using sendmail or SMTP

July 8, 2015Updated: May 23, 2024

How to send mail in CakePHP 2.x First you have to configure your cakephp for sending mail. Go to: App/Config/email.php Now there are two method you can use: Using sendmail function Using SMTP For sendmail : public $default = array( ‘transport’ => ‘Mail’, ‘from’ => ‘[email protected]’, ‘charset’ => ‘utf-8’, ‘headerCharset’ => ‘utf-8’, ); For SMTP: […]

How to send mail in CakePHP 2.x
First you have to configure your cakephp for sending mail.
Go to:

App/Config/email.php

Now there are two method you can use:

  1. Using sendmail function
  2. Using SMTP

For sendmail :

public $default = array( 'transport' => 'Mail', 'from' => '[email protected]', 'charset' => 'utf-8', 'headerCharset' => 'utf-8', ); 

For SMTP:

public $smtp = array( 'transport' => 'Smtp', 'from' => array([email protected]' => Sender name), 'host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 30, 'username' => [email protected]', 'password' => PASSWORD, 'client' => null, 'log' => false, 'charset' => 'utf-8', 'headerCharset' => 'utf-8', ); 

Now you have setup you mail config file.
Now we will send mail:

$Email = new CakeEmail('smtp'); // Replace Smtp to default if you don’t want send mail from SMTP $Email->to('[email protected]'); $Email->emailFormat('html'); $Email->template('default')->viewVars( array('body'=>"Hi this is a mail from cakePHP")); // pass your variables here. $Email->subject('My First Mail from cakephp'); $Email->from ('[email protected]'); $Email->send(); 

To edit or customize your mail template you have to edit/create your email template file:

app/View/Emails/html/default.ctp
 

Hi

 
for more information you can check CakePHP documentation.
 
Post on demand by one of my visitor “Nadim”.

← Back to all blogs