无法在Symfony 1.31中发送邮件

时间:2010-02-03 01:29:24

标签: symfony1 email swiftmailer

我正在尝试使用以下方法在我的操作类中发送电子邮件:

  public function executeTestnewmail()
  {
    // send an email to the affiliate
    $message = $this->getMailer()->compose(
      array('my_email_address_here' => 'Jobeet Bot'),
      'recipient_address_here',
      'Jobeet affiliate token',
      <<<EOF
Your Jobeet affiliate account has been activated.

Your token is 1.

The Jobeet Bot.
EOF
    );

    $this->getMailer()->send($message);

    $this->redirect('@homepage');
  }

上面的代码是(几乎)逐字(即几乎完全)Jobeet示例的副本 - 但是当我为发件人和收件人使用正确的电子邮件地址时,不会发送邮件,而是会超时。

我在日志文件中收到以下错误消息:

致命错误:第78行$(SYMFONY_ROOT_DIR)\ lib \ log \ sfWebDebugLogger.class.php超过30秒的最大执行时间调用堆栈:0.0003 66216 1. {main}(

这条线索对任何人都有什么建议吗? 有没有人真的设法使用SF1.3 +发送电子邮件?

顺便说一句,我可以通过简单地使用mail()命令(我在Symfony测试中使用相同的发件人/收件人地址)从我的机器发送电子邮件没问题,所以我知道SMTP等正常工作我的机器

[编辑]

完整堆栈跟踪包含在下面:

Fatal error: Maximum execution time of 30 seconds exceeded in $(SF_ROOT_DIR)\lib\log\sfWebDebugLogger.class.php on line 78 Call Stack: 0.0003 66216 
1.  {main}() $(PROJECT_DIR)\web\frontend_dev.php:0 0.2684 10774096
2.  sfContext->dispatch() $(PROJECT_DIR)\web\frontend_dev.php:13 0.2684 10774240 
3.  sfFrontWebController->dispatch() $(SF_ROOT_DIR)\lib\util\sfContext.class.php:170 0.2691 10795440 
4.  sfController->forward() $(SF_ROOT_DIR)\lib\controller\sfFrontWebController.class.php:48 0.3280 11707400 
5.  sfFilterChain->execute($(SF_ROOT_DIR)\lib\controller\sfController.class.php:235 0.3286 11715304 
6.  sfRenderingFilter->execute() $(SF_ROOT_DIR)\lib\filter\sfFilterChain.class.php:53 0.3286 11715768 
7.  sfFilterChain->execute() $(SF_ROOT_DIR)\lib\filter\sfRenderingFilter.class.php:33 0.3292 11725920 
8.  sfGuardRememberMeFilter->execute() $(SF_ROOT_DIR)\lib\filter\sfFilterChain.class.php:53 0.3292 11727680 
9.  sfFilterChain->execute() $(PROJECT_DIR)\apps\frontend\lib\sfGuardRememberMeFilter.class.php:65 0.3298 11740192 
10. nonMemberCheckFilter->execute() $(SF_ROOT_DIR)\lib\filter\sfFilterChain.class.php:53 0.3299 11742280 
11. sfFilterChain->execute() $(PROJECT_DIR)\apps\frontend\lib\nonMemberCheckFilter.class.php:68 0.3305 11757240 
12. sfCacheFilter->execute() $(SF_ROOT_DIR)\lib\filter\sfFilterChain.class.php:53 0.3426 11776320 
13. sfFilterChain->execute() $(SF_ROOT_DIR)\lib\filter\sfCacheFilter.class.php:65 0.3433 11793568 
14. sfValidationExecutionFilter->execute() $(SF_ROOT_DIR)\lib\filter\sfFilterChain.class.php:53 0.3434 11795872 
15. sfValidationExecutionFilter->handleAction() $(SF_ROOT_DIR)\lib\plugins\sfCompat10Plugin\lib\filter\sfValidationExecutionFilter.class.php:43 0.3600 11796712 
16. sfValidationExecutionFilter->executeAction() $(SF_ROOT_DIR)\lib\plugins\sfCompat10Plugin\lib\filter\sfValidationExecutionFilter.class.php:87 0.3600 11797136 
17. sfActions->execute() (SF_ROOT_DIR)\lib\plugins\sfCompat10Plugin\lib\filter\sfValidationExecutionFilter.class.php:169 0.3608 11820384 
18. homeActions->executeTestnewmail() $(SF_ROOT_DIR)\lib\action\sfActions.class.php:60 0.4796 13858992 
19. sfMailer->send() $(PROJECT_DIR)\apps\frontend\modules\home\actions\actions.class.php:621 0.4797 13859496 
20. Swift_Mailer->send() $(SF_ROOT_DIR)\lib\mailer\sfMailer.class.php:294 0.4797 13860016 
21. Swift_Transport_AbstractSmtpTransport->start() $(SF_ROOT_DIR)\lib\vendor\swiftmailer\classes\Swift\Mailer.php:74 0.4850 13876104 
22. Swift_Transport_StreamBuffer->initialize() $(SF_ROOT_DIR)\lib\vendor\swiftmailer\classes\Swift\Transport\AbstractSmtpTransport.php:101 0.4850 13876448 
23. Swift_Transport_StreamBuffer->_establishSocketConnection() $(SF_ROOT_DIR)\lib\vendor\swiftmailer\classes\Swift\Transport\StreamBuffer.php:70 0.4850 13877896 
24. fsockopen() $(SF_ROOT_DIR)\lib\vendor\swiftmailer\classes\Swift\Transport\StreamBuffer.php:233 30.4772 13879672
25. sfWebDebugLogger->handlePhpError() $(SF_ROOT_DIR)\lib\log\sfWebDebugLogger.class.php:0 

我在($ PROJECT_DIR)/apps/frontend/config/factories.yml中指定的邮件配置是:

# this is commented out because I want to be able to send mails in dev environment
#dev:
#  mailer:
#    param:
#      delivery_strategy: none

  test:
    mailer:
      param:
        delivery_strategy: none


  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:   ~

[EDIT2]

我的php.ini设置(关于SMTP)是:

[mail function]
; For Win32 only.
;SMTP = localhost
SMTP = smtp.my-isp-address-here
smtp_port = 25

2 个答案:

答案 0 :(得分:3)

php.ini文件中的另一个SMTP配置与factories.yml中的配置相同 首先,您将ISP作为SMTP服务器提供,然后在您自己的机器(localhost)中提供。但我猜你的机器上没有运行SMTP服务器,这就是它必须(我认为):

 all:
    mailer:
      class: sfMailer
      param:
        logging:           %SF_LOGGING_ENABLED%
        charset:           %SF_CHARSET%
        delivery_strategy: realtime
        transport:
          class: Swift_SmtpTransport
          param:
            host:       smtp.your-isp-address-here
            port:       25
            encryption: ~
            username:   ~
            password:   ~

但您也可以设置swift邮件程序以通过PHP mail()函数发送电子邮件。然后,这将使用php.ini中的配置:

all:
    mailer:
      class: sfMailer
      param:
        logging:           %SF_LOGGING_ENABLED%
        charset:           %SF_CHARSET%
        delivery_strategy: realtime
        transport:
          class: Swift_MailTransport

可以在More with Symfony - Chapter Emails;)

中阅读此内容以及更多内容

答案 1 :(得分:1)

我使用Symfony 1.3.1管理电子邮件发送 我真的不知道您的应用程序中发生了什么,但这是我的代码和conf,这对我很有用。

<强>控制器

<?php
... 
$message = Swift_Message::newInstance()
  ->setFrom('sender@foo.com')
  ->setTo('recipient@bar.com')
  ->setSubject('subject')
  ->setBody('body')
  ->setContentType('text/html');

$this->getMailer()->send($message);
...

<强> factories.yml文件

all:
  mailer:
    class: sfMailer
    param:
      delivery_strategy: spool
      spool_class:       Swift_FileSpool
      spool_arguments:   [/path/to/swift_spool]