Swift mail and Symfony ([Connection refused #111])
I am getting this error when I try to send an em开发者_运维知识库ail using the Symfony framework. I had this problem a while back and rember (vaguely), that I had to change my php.ini settings and match them to my /app/config/factories.yml to get it to work.
Unfortunately, I had to rebuild my machine recently, and mail has now stopped working - and unfortunately, I can't remember what I did the last time to get ot to work.
Here is a snippet of the contents of my app/config/factories.yml file:
all:
mailer:
class: sfMailer
param:
logging: %SF_LOGGING_ENABLED%
charset: %SF_CHARSET%
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: localhost
port: 25
encryption: ~
username: ~
password: ~
Note: The indentaion above may be wrong due to being pasted in this console - don't get side tracked by that. The YML is fine on my machine.
This is the logged error message when I try to send an email:
[19-Feb-2011 14:50:13] PHP 20. userActions->executeRegisterComplete() /lib/vendor/symfony/symfony-1.3.8/lib/action/sfActions.class.php:60
[19-Feb-2011 14:50:13] PHP 21. sfMailer->send() /path/to/actions.class.php:355
[19-Feb-2011 14:50:13] PHP 22. Swift_Mailer->send() /lib/vendor/symfony/symfony-1.3.8/lib/mailer/sfMailer.class.php:300
[19-Feb-2011 14:50:13] PHP 23. Swift_Transport_AbstractSmtpTransport->start() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Mailer.php:74
[19-Feb-2011 14:50:13] PHP 24. Swift_Transport_StreamBuffer->initialize() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/AbstractSmtpTransport.php:101
[19-Feb-2011 14:50:13] PHP 25. Swift_Transport_StreamBuffer->_establishSocketConnection() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php:70
[19-Feb-2011 14:50:13] PHP 26. fsockopen() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php:233
[19-Feb-2011 14:50:13] Connection could not be established with host localhost [Connection refused #111]
I've always put like and always have worked; I simply do not use localhost smtp service.
all:
mailer:
param:
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: "xxx@gmail.com"
password: xxx-password
The problem could be that you do not have disabled the mail sent in development environment. You have to complete your config_dev.yml like this:
imports:
- { resource: config.yml }
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: true
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
assetic:
use_controller: true
swiftmailer:
disable_delivery: true
You have to set:
- disable_delivery: true (not send email)
- intercept_redirects: true (if you want to see the email in your debug bar)
I had same error on my hosting provider. I have fixed it by editing factories.yml indentation. Also check your username/password values.
精彩评论