smtp not working on 1and1
<p>I'm using 1and1 server to host my CakePHP 3.2 application</p>

<p>This is how, I have configured email component on CakePHP</p>

<pre><code>'EmailTransport' =&gt; [
    'default' =&gt; [
        'className' =&gt; 'Smtp',
        // The following keys are used in SMTP transports
        'host' =&gt; 'smtp.1and1.com',
        'port' =&gt; 587,
        'timeout' =&gt; 30,
        'username' =&gt; 'noreply@mywebsite.com',
        'password' =&gt; 'password',
        'client' =&gt; null,
        'tls' =&gt; null,
        'url' =&gt; env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],
</code></pre>

<p>But this is not working and no email is sent and gives <code>Connection Time out</code> after 30 seconds.</p>

<p>From 1and1 email configuration page. It says </p>

<pre><code>Outgoing port (TLS must be activated) 
</code></pre>

<p>How to enable/configure TLS in CakePHP ?</p>

<blockquote>
  <p>Edit 2</p>
</blockquote>

<p>the error stack shows 
<strong>SmtpTransport.php</strong></p>

<pre><code>protected function _connect()
{
    $this-&gt;_generateSocket();
    if (!$this-&gt;_socket-&gt;connect()) {     // marked this line
       throw new SocketException('Unable to connect to SMTP server.');
    }
    $this-&gt;_smtpSend(null, '220');
</code></pre>

<p><strong>Action to send email</strong></p>

<pre><code>public function sendEmail($user_id = null, $email_id = null, $hash = null, $request = null)
{
    switch($request) {
      case 'register' : $subject = 'Account Confirmation';
                        $message = 'You have successfully registered. Click below link to verify it http://website.com/sellers/verify/'.$email_id.'/'.$hash;
        break;
    }

    $email = new Email('default');
    if ($email-&gt;from(['anujsharma9196@gmail.com' =&gt; 'Argo Systems'])
          -&gt;to((string)$email_id)
          -&gt;subject($subject)
          -&gt;send($message)) {

      return true;
    } else {
      return false;
    }
}
</code></pre>

<p>and calling this function from same controller by</p>

<pre><code>$this-&gt;sendEmail($user-&gt;id, $user-&gt;email, $hash, 'register');
</code></pre>