Sending emails from 1and1 smtp server using Zend Framework
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:
I'm getting over and over again the sa开发者_StackOverflow中文版me 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...
I'm using quite common configuration:
email.configTransport.auth = "login" email.configTransport.username = "my@mail.com" email.configTransport.password = "password" email.configTransport.host = "smtp.1and1.pl"
And then in bootstrap I'm setting default transport:
protected function _initDefaultEmailTransport(){
$configTransport = $this->getOption('email');
$tr = new Zend_Mail_Transport_Smtp($configTransport['configTransport']['host'],
$configTransport['configTransport']);
Zend_Mail::setDefaultTransport($tr);
}
- What's interesting the most it works on my localhost (also via Thunderbird). So I gues that configuration is ok and smtp server works.
- 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?
I'll be greatful for any ideas what could be wrong.
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.
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutpath = APPLICATION_PATH "/layouts/scripts/"
autoloaderNamespaces[] = "Doctrine"
doctrine.dsn = "mysql://...."
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures"
doctrine.models_path = APPLICATION_PATH "/models"
doctrine.migrations_path = APPLICATION_PATH "/../doctrine/migrations"
doctrine.sql_path = APPLICATION_PATH "/../doctrine/data/sql"
doctrine.yaml_schema_path = APPLICATION_PATH "/../doctrine/schema"
doctrine.generate_models_options.pearStyle = true
doctrine.generate_models_options.generateTableClasses = true
doctrine.generate_models_options.generateBaseClasses = true
doctrine.generate_models_options.baseClassPrefix = "Base_"
doctrine.generate_models_options.baseClassesDirectory =
doctrine.generate_models_options.classPrefixFiles = false
doctrine.generate_models_options.classPrefix = "Application_Model_"
resources.mail.transport.type = "smtp"
resources.mail.transport.host = "smtp.gmail.com"
resources.mail.transport.auth = "login"
resources.mail.transport.ssl = "tls"
resources.mail.transport.username = "username"
resources.mail.transport.password = "pass"
resources.mail.transport.register = true
autoloaderNamespaces[] = "ZC"
[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
And here's full error message:
Stack trace:
#0 /homepages/46/d339149978/htdocs/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://smtp.gmai...')
#1 /homepages/46/d339149978/htdocs/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect()
#2 /homepages/46/d339149978/htdocs/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /homepages/46/d339149978/htdocs/library/Zend/Mail.php(1178): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#4 /homepages/46/d339149978/htdocs/application/controllers/ContactController.php(97): Zend_Mail->send()
#5 /homepages/46/d339149978/htdocs/application/controllers/ContactController.php(74): ContactController->sendContactMail(Array)
#6 /homepages/46/d339149978/htdocs/library/Zend/Controller/Action.php(513): ContactController->sendAction()
#7 /homepages/46/d339149978/htdocs/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('sendAction')
#8 /homepages/46/d339149978/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->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->dispatch()
#10 /homepages/46/d339149978/htdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 /homepages/46/d339149978/htdocs/public/index.php(27): Zend_Application->run()
#12 {main}
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...
I've spent hours trying everything to get 1and1 servers to accept SMTP mail. It works from a remote testing server (using the following:
$mailhost = 'auth.smtp.1and1.co.uk';
$mailconfig = array('auth' => 'login',
'username' => 'myaddress@example.com',
'password' => 'myPassword');
$transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
When I deploy it on 1and1 I get "connection refused". Other forums maintain that this is because 1and1 won't allow SMTP on their own servers, so you have to use Sendmail() instead. The above script then becomes:-
$transport = new Zend_Mail_Transport_Sendmail('-freturn_to_myaddress@example.com');
Zend_Mail::setDefaultTransport($transport);
(Note, I've put a return address in)
This will work on 1and1 servers.
Chris
It may not be "the" solution, but it can help you to be sure that your manual settings are not generating errors.
resources.mail.transport.type = "smtp"
resources.mail.transport.host = "smtp.gmail.com"
resources.mail.transport.auth = "login"
resources.mail.transport.ssl = "tls"
resources.mail.transport.username = "yourlogin" ; without the @ part
resources.mail.transport.password = "yourpasswd"
resources.mail.transport.register = true
Replace yourlogin
& yourpasswd
by yours, and it should work.
The last option, register
registers the default transport you previously set.
As stated in your comment, if it works locally, here is a check list:
- Make sure your
APPLICATION_ENV
doesn't override your settings (production
&development
) - Make sure
OpenSSL
is installed on your host (it is needed to connect to Gmail with a secure connection) - Post your error message
- Post your config.ini
I'm getting over and over again the same error "Message: Connection refused" no matter what smtp I'm trying to use
"Connection refused" means that either the remote server rejected the connection, or the local machine has a firewall or security policy that prevented the connection from being created to begin with.
If you are getting that error no matter what SMTP server you are connecting to, then your hosting provider is blocking the connection. You will need to contact them ask about the problem.
Be aware that 1&1 has been an awful hosting provider for over a decade and should be avoided. Even Dreamhost, one of the cheapest providers out there, provides better service.
精彩评论