title: CakePHP email configuration
body: <p>I want to use CakePHP Email to send emails to users with new passwords when a user has forgotten their password. If the user has forgotten their password they will be required to enter their username and corresponding email. The system will check if the username and email match in the database and if so create a random password and send it to the users email account. I'm a beginner and I'm not sure if I'm doing it properly. My code is as follows:</p>
  
  <p>employeesController:</p>
  
  <pre><code>&lt;?php
  App::uses('AppController', 'Controller');
  App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
  App::uses('CakeEmail', 'Network/Email');
  
  class EmployeesController extends AppController {
  
  //some code
  
   public function forgotpassword()
      {
          $username=$this-&gt;request-&gt;data['fusername'];
          //App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
          //$passwordHasher = new SimplePasswordHasher();
          //$password = $passwordHasher-&gt;hash($this-&gt;request-&gt;data['password']);
          $emailaddress=$this-&gt;request-&gt;data['emailadd'];
          $msg = $this-&gt;Employee-&gt;getUserPassword($username,$emailaddress);
          if($msg)
          {
  
              foreach ($msg as $userdetails)
              {
                  $userhashedpass=$userdetails['Employee']['employee_pw'];//see access level here
                  $userid=$userdetails['Employee']['id'];
                  $useremail=$userdetails['Employee']['employee_email'];
  
  
              }
              $newpassword="$userhashedpass[0]$userhashedpass[4]$userhashedpass[13]$userhashedpass[8]$userhashedpass[11]$userhashedpass[12]";
  
              //send email
  
              $Email = new CakeEmail();
              $Email-&gt;from(array('anuja_f@hotmail.com' =&gt; 'CentreVision CRM'))
                  -&gt;to($useremail)
                  -&gt;subject('New Password')
                  -&gt;send('Your new password is $newpassword ');
  
             /* $to = $useremail;
              $subject = "Your New Password";
              $txt = "Your new password is $newpassword ";
              $headers = "From: admin@centervision.com" . "\r\n";
  */
  //send email to the employee
  
  
              // $reply=$this-&gt;Employee-&gt;updatenewpassword($username,$emailaddress,$newpassword);
              $data = array('id' =&gt; $userid, 'employee_pw' =&gt; $newpassword);
              // This will update Recipe with id 10
              $this-&gt;Employee-&gt;save($data);
              //$this-&gt;set('msg',$userhashedpass);
              //$this-&gt;set('newpassword',$newpassword);
              $errormsg="Email has been sent to registered email address linked to this username";
              //comment out next line to not display the new password on the screen once smtp is configured
              $this-&gt;set('newpassword',$newpassword);
              $this-&gt;set('errorfor',$errormsg);
              $this-&gt;render("../Pages/home");
              $this-&gt;layout = '../Pages/home';
          }
          else{
              $errormsg="Username and Email does not match";
              $this-&gt;set('errorfor',$errormsg);
              $this-&gt;render("../Pages/home");
              $this-&gt;layout = '../Pages/home';
          }
  
      }
  
  //some code
  
  }
  </code></pre>
  
  <p>And my app/config/email.php:</p>
  
  <pre><code>class EmailConfig {
  
      public $default = array(
          'transport' =&gt; 'Mail',
          'from' =&gt; 'anuja_f@hotmail.com',
          //'charset' =&gt; 'utf-8',
          //'headerCharset' =&gt; 'utf-8',
      );
  
      public $smtp = array(
          'transport' =&gt; 'Smtp',
          'from' =&gt; array('site@localhost' =&gt; 'My Site'),
          'host' =&gt; 'localhost',
          'port' =&gt; 25,
          'timeout' =&gt; 30,
          'username' =&gt; 'user',
          'password' =&gt; 'secret',
          'client' =&gt; null,
          'log' =&gt; false,
          //'charset' =&gt; 'utf-8',
          //'headerCharset' =&gt; 'utf-8',
      );
  
      public $fast = array(
          'from' =&gt; 'you@localhost',
          'sender' =&gt; null,
          'to' =&gt; null,
          'cc' =&gt; null,
          'bcc' =&gt; null,
          'replyTo' =&gt; null,
          'readReceipt' =&gt; null,
          'returnPath' =&gt; null,
          'messageId' =&gt; true,
          'subject' =&gt; null,
          'message' =&gt; null,
          'headers' =&gt; null,
          'viewRender' =&gt; null,
          'template' =&gt; false,
          'layout' =&gt; false,
          'viewVars' =&gt; null,
          'attachments' =&gt; null,
          'emailFormat' =&gt; null,
          'transport' =&gt; 'Smtp',
          'host' =&gt; 'localhost',
          'port' =&gt; 25,
          'timeout' =&gt; 30,
          'username' =&gt; 'user',
          'password' =&gt; 'secret',
          'client' =&gt; null,
          'log' =&gt; true,
          //'charset' =&gt; 'utf-8',
          //'headerCharset' =&gt; 'utf-8',
      );
  
  }
  </code></pre>
  
  <p>At the moment when I enter username and email i get the following error:</p>
  
  <p>mail(): Failed to connect to mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use ini_set()</p>
  
  <p>Can someone please help me? </p>