free hit counter

Sending Email Using Cakephp via SMPT 2

CakeEmail

class CakeEmail(mixed $config = null)

CakeEmail is a new class to send email. With this class you can send email from any place of your application. In addition to using the EmailComponent from your controller, you can also send mail from Shells, and Models.

This class replaces the EmailComponent and gives more flexibility in sending emails. For example, you can create your own transports to send email instead of using the provided smtp and mail.

Create a function 

  1. public function smpt_mail()  
  2.     {  
  3.       
  4.     $this->Email->sendAs = ‘html’;  
  5.     $this->Email->from = “abc”;  
  6.     $this->Email->to = ‘abc@xyz.com’;  
  7.     $this->Email->subject = “test mal”;  
  8.         $this->Email->smtpOptions = array(  
  9.         ‘port’=>‘465’,  
  10.         ‘timeout’=>’30’,  
  11.         ‘host’ => ‘ssl://smtp.gmail.com’,  
  12.         ‘username’=>‘gmail id ‘,  
  13.         ‘password’=>‘gmail passwrd’,  
  14.         );  
  15.         $this->Email->delivery = ‘smtp’;  
  16.         if ($this->Email->send($body)) {  
  17.             return 1;  
  18.         } else {  
  19.             echo $this->Email->smtpError;  
  20.         }  
  21.     }  

Now call in any controller .

if you use this function in custom components then include this line

  1. public $components = array(‘Cookie’,‘Session’,‘Email’);  

2 thoughts on “Sending Email Using Cakephp via SMPT

  1. Reply Isabell Sep 14,2014 6:47 pm

    Finally i quit my regular job, now i earn a lot of money
    on-line you should try too, just type in google – blackhand
    roulette system

  2. Reply Selene Jan 5,2015 2:16 pm

    Hello, you post interesting content on your blog, you can get
    much more visitors, just search in google for – augo’s tube traffic

Leave a Reply