Tejas Rana
  • Home
  • About
  • Experience
  • Skills
  • Blogs
  • Technology
  • Contact
smtp-4
April 26 2016

Send email in Cakephp using SMTP With Source and Video

tejas CakePHP

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
<html>
<h1>Hi</h1>
<p><?php echo $body; ?></p>
</html>

 

Icon

Cakephp with SMTP Demo

1 file(s) 0.00 KB
Download

for more information you can check CakePHP documentation.

Getting Started with Elixir Programming Language Auto Screen Rotate/G-Sensor Issue in Windows 10 Tablet

Related Posts

CakePHP, PHP

The Most Common Mistakes CakePHP Developers Make : A Tutorial for Beginners

CakePHP

How to send email in Cakephp using sendmail or SMTP

CakePHP

Getting Started with CakePHP

Categories

  • .NET
  • Android
  • Angular
  • CakePHP
  • CSS
  • Devops
  • Drupal
  • Infi MVC
  • iOS
  • Javascript
  • Magento
  • Meteor
  • MongoDB
  • Opencart
  • Other
  • PHP
  • Python
  • Ruby
  • Tips & Tricks
  • WordPress

Recent Posts

  • Simplify Product Filtering by Category and Store ID in the Admin Panel with Our Powerful OpenCart 3.x Free Extension
  • Opencart 3.x Set currency based on user’s IP [Free Extension]
  • Anatomy of A Coronavirus-Proof Business[Infographic]
  • Opencart 3 Social Login Extension [FREE]
  • What is NGRX and Use of NGRX

Recent Comments

  • Nilesh on What is State Management in Angular? How to improve Performance?
  • Dinesh on Use Magento If You're Serious About eCommerce
  • Virendra on Use Magento If You're Serious About eCommerce
  • Tejas Rana on Show limited words in PHP from string with HTML tags
  • nadim on Show limited words in PHP from string with HTML tags
Tejas Rana
© Tejas Rana 2025