title: How do I use the CakePHP Email Component?
body: <p>I am new to CakePHP and trying desperately to learn!</p>
  
  <p>My most recent struggle is with the Email Component.</p>
  
  <p>I have a contract. When I create the contract, I add a user. When I save the new contract...for the first time, I want to send an email to the user in that contract that allows them to click on a link back to the contract, and then accept or reject the contract.</p>
  
  <p>How do I send this email?</p>
  
  <p>The more details I can get, answer-wise, the better. Everything I have read out there is surprisingly confusing. Do I need to configure smtp settings? How do I grab the user in the contract after it has been saved and pass it and the link to the contract on to the email? How do I know if the email has been sent, without going and checking my email every single time?</p>
  
  <p>Here is the code I have in my contracts_controller.php for the email sending function: (A Contract belongsTo a User, and a User hasMany Contracts.)</p>
  
  <pre><code>function _sendContractEmail($id) {
          $this-&gt;Email-&gt;smtpOptions = array(
          'port'=&gt;'465',
          'timeout'=&gt;'30',
          'host'=&gt;'ssl://smtp.gmail.com',
          'username'=&gt;'username',
          'password'=&gt;'password'
          );
          $this-&gt;Email-&gt;delivery = 'smtp';
          $User = $this-&gt;Contract-&gt;User-&gt;read(null,$id);
          $this-&gt;Email-&gt;to = 'jeremiah@jeremiahotis.com';
          $this-&gt;Email-&gt;subject = '';
          $this-&gt;Email-&gt;replyTo = 'no-reply@goodvaluation.com';
          $this-&gt;Email-&gt;from = 'Jeremiah Oits &lt;jeremiah@jeremiaotis.com&gt;';
          $this-&gt;Email-&gt;template = 'simple_message';
          $this-&gt;Email-&gt;sendAs = 'html';
          $this-&gt;set('User', $User);
          $this-&gt;Email-&gt;_debug = true;
          $this-&gt;Email-&gt;send('Test Email');
          $this-&gt;redirect(array('controller'=&gt;'contracts', 'action'=&gt;'index'));
      }
  </code></pre>
  
  <p>Here is the code I have in my contracts_controller.php add() function:</p>
  
  <pre><code>function add() {
          if (!empty($this-&gt;data)) {
              $this-&gt;Contract-&gt;create();
              if ($this-&gt;Contract-&gt;save($this-&gt;data)) {
                  $this-&gt;Session-&gt;setFlash(__('The Contract has been saved', true));
                  $this-&gt;_sendContractEmail($this-&gt;Contract-&gt;User-&gt;id);
              } else {
                  $this-&gt;Session-&gt;setFlash(__('The Contract could not be saved. Please, try again.', true));
              }
  </code></pre>
  
  <p>And, this is at the top of my contracts_controller.php file after the $name and $helpers:</p>
  
  <pre><code>var $components = array('Email');
  </code></pre>
  
  <p>I guess I should point out that I was having trouble with the template, so to test it, I included the body of the email directly in the send(), and I specified the to email address rather than using a variable. Still...nothing! No error, no email.</p>
  
  <p>Any help would be greatly appreciated! I really have no idea what I am doing wrong!</p>
  
  <p>Thanks,</p>
  
  <p>Jeremiah</p>