title: Sending emails from 1and1 smtp server using Zend Framework
body: <p>I know there have been a plenty of questions about smtp, 1and1 hosting and Zend Framework already. I've been reading them for hours and still got nothing (maybe I've omitted the most important one?). So lets get to the point:</p>
  <ul>
  <li><p>I'm getting over and over again the
  same error “Message: Connection
  refused „, no matter what smtp I'm
  trying to use. I understand that there could be issues with outer servers like gmail (which I've also tried), but  1and1 smpt...</p>
  </li>
  <li><p>I'm using quite common configuration:</p>
  <p>email.configTransport.auth      =   &quot;login&quot;
  email.configTransport.username  =   &quot;my@mail.com&quot;
  email.configTransport.password  =   &quot;password&quot;
  email.configTransport.host      =   &quot;smtp.1and1.pl&quot;</p>
  </li>
  </ul>
  <p>And then in bootstrap I'm setting default transport:</p>
  <pre><code>protected function _initDefaultEmailTransport(){
      
      $configTransport = $this-&gt;getOption('email');
  
      $tr = new Zend_Mail_Transport_Smtp($configTransport['configTransport']['host'],
                                          $configTransport['configTransport']);
      
      Zend_Mail::setDefaultTransport($tr);
  }
  </code></pre>
  <ul>
  <li>What's interesting the most it works on
  my localhost (also via Thunderbird). So I gues that configuration is ok and smtp server works.</li>
  <li>I've been trying on ports 25 and 587.
  Same paroblem.
  If i change password for a wrong one, I'm getting the same error again, so it looks like I've got problem at the connetion stage, doesn't it?</li>
  </ul>
  <p>I'll be greatful for any ideas what could be wrong.</p>
  <hr />
  <p>I don't see place where it could be overwritten. Beside that I tried with both production and development configurations. OpenSSL is enabled for sure, I've check that already. Here's my config file.</p>
  <pre><code>[production]
  phpSettings.display_startup_errors = 0
  phpSettings.display_errors = 0
  includePaths.library = APPLICATION_PATH &quot;/../library&quot;
  bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot;
  bootstrap.class = &quot;Bootstrap&quot;
  appnamespace = &quot;Application&quot;
  resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;
  resources.frontController.params.displayExceptions = 0
  resources.layout.layoutpath = APPLICATION_PATH &quot;/layouts/scripts/&quot;
  
  autoloaderNamespaces[] = &quot;Doctrine&quot;
  
  doctrine.dsn = &quot;mysql://....&quot;
  
  doctrine.data_fixtures_path = APPLICATION_PATH &quot;/../doctrine/data/fixtures&quot;
  doctrine.models_path = APPLICATION_PATH &quot;/models&quot;
  doctrine.migrations_path = APPLICATION_PATH &quot;/../doctrine/migrations&quot;
  doctrine.sql_path = APPLICATION_PATH &quot;/../doctrine/data/sql&quot;
  doctrine.yaml_schema_path = APPLICATION_PATH &quot;/../doctrine/schema&quot;
  
  doctrine.generate_models_options.pearStyle = true
  doctrine.generate_models_options.generateTableClasses = true
  doctrine.generate_models_options.generateBaseClasses = true
  doctrine.generate_models_options.baseClassPrefix = &quot;Base_&quot;
  doctrine.generate_models_options.baseClassesDirectory =
  doctrine.generate_models_options.classPrefixFiles = false
  doctrine.generate_models_options.classPrefix = &quot;Application_Model_&quot;
  
  resources.mail.transport.type = &quot;smtp&quot;
  resources.mail.transport.host = &quot;smtp.gmail.com&quot;
  resources.mail.transport.auth = &quot;login&quot;
  resources.mail.transport.ssl = &quot;tls&quot;
  resources.mail.transport.username = &quot;username&quot;
  resources.mail.transport.password = &quot;pass&quot;
  resources.mail.transport.register = true
  
  autoloaderNamespaces[] = &quot;ZC&quot;
  
  [staging : production]
  
  [testing : production]
  phpSettings.display_startup_errors = 1
  phpSettings.display_errors = 1
  
  [development : production]
  phpSettings.display_startup_errors = 1
  phpSettings.display_errors = 1
  resources.frontController.params.displayExceptions = 1
  </code></pre>
  <p>And here's full error message:</p>
  <pre><code>Stack trace:
  
  #0 /homepages/46/d339149978/htdocs/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract-&gt;_connect('tcp://smtp.gmai...')
  #1 /homepages/46/d339149978/htdocs/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp-&gt;connect()
  #2 /homepages/46/d339149978/htdocs/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp-&gt;_sendMail()
  #3 /homepages/46/d339149978/htdocs/library/Zend/Mail.php(1178): Zend_Mail_Transport_Abstract-&gt;send(Object(Zend_Mail))
  #4 /homepages/46/d339149978/htdocs/application/controllers/ContactController.php(97): Zend_Mail-&gt;send()
  #5 /homepages/46/d339149978/htdocs/application/controllers/ContactController.php(74): ContactController-&gt;sendContactMail(Array)
  #6 /homepages/46/d339149978/htdocs/library/Zend/Controller/Action.php(513): ContactController-&gt;sendAction()
  #7 /homepages/46/d339149978/htdocs/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action-&gt;dispatch('sendAction')
  #8 /homepages/46/d339149978/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard-&gt;dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
  #9 /homepages/46/d339149978/htdocs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front-&gt;dispatch()
  #10 /homepages/46/d339149978/htdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap-&gt;run()
  #11 /homepages/46/d339149978/htdocs/public/index.php(27): Zend_Application-&gt;run()
  #12 {main}  
  </code></pre>
  <p>On Sunday I've send an e-mail to 1and1 asking if there any problems with sending e-mails via SMTP. Today I've received an answer saying that everything works fine, and I have to check my scripts...</p>