2010-06-15 56 views
1

我使用的Symfony + SwiftMailer和SwiftMailer得到以下错误:为什么SwiftMailer抛出“内部服务器错误”?

500 | Internal Server Error | Swift_TransportException 
Expected response code 220 but got code "", with message "" 

,不能找出原因。我使用hMailServer我的本地机器上,并且有安装我的factories.yml文件的文件(如我使用的Symfony)如下:

mailer: 
    class: sfMailer 
    param: 
     logging: %SF_LOGGING_ENABLED% 
     charset: %SF_CHARSET% 
     delivery_strategy: realtime 
     transport: 
     class: Swift_SmtpTransport 
     param: 
      host: splodge.loc 
      port: 25 
      encryption: ~ 
      username: ~ 
      password: ~ 

我用下面的代码来发送:

$message = $this->getMailer()->compose(
    '[email protected]', 
    '[email protected]', 
    'Reset Password', 
    'Message' 
); 
$result = $this->getMailer()->send($message); 

有没有人有过这样的问题?

我发现有时和非常随机的发送过程中,但每隔一段时间,我都会收到上述错误消息。因此,不断刷新发送邮件的页面,不可预知地失败,并且随着代码有时起作用,很难弄清楚什么是错误的。

任何帮助将不胜感激!


进一步的调查表明,SMTP服务器并发送[220本地主机ESMTP],但考虑看看hMailServer登录后,我发现了以下内容:

"TCPIP" 5232 "2010-06-16 11:40:54.043" "TCPConnection - Posting AcceptEx on 0.0.0.0:25" 
"DEBUG" 5232 "2010-06-16 11:40:54.043" "Creating session 51" 
"SMTPD" 5232 51 "2010-06-16 11:40:54.043" "127.0.0.1" "SENT: 220 localhost ESMTP" 
"DEBUG" 5296 "2010-06-16 11:40:54.199" "The read operation failed. Bytes transferred: 0 Remote IP: 127.0.0.1, Session: 51, Code: 10054, Message: An existing connection was forcibly closed by the remote host" 
"DEBUG" 5296 "2010-06-16 11:40:54.199" "Ending session 51" 

难道说SwiftMailer是HELO/EHLOing太早了,这只是一个时间问题?我可以延迟HELO传输吗?

的上等原木,当事情实际上发送如下所示:

"TCPIP" 5232 "2010-06-16 11:42:21.278" "TCPConnection - Posting AcceptEx on 0.0.0.0:25" 
"DEBUG" 5232 "2010-06-16 11:42:21.294" "Creating session 54" 
"SMTPD" 5232 54 "2010-06-16 11:42:21.294" "127.0.0.1" "SENT: 220 localhost ESMTP" 
"SMTPD" 5224 54 "2010-06-16 11:42:21.294" "127.0.0.1" "RECEIVED: EHLO splodge.loc" 

所以它必须与HELO/EHLO确认的事情。请指教! :)

+0

问题可能在于您的主机。你为什么不尝试Gmail,看看你是否遇到同样的问题。 – Dziamid 2011-06-11 13:06:57

回答

0

管理通过创建一个循环,重试邮件发送得到这个工作...

$sendResult = false; 
do 
{ 
    try 
    { 
     $message = Swift_Message::newInstance() 
      ->setFrom('[email protected]', 'Mr.Postman') 
      ->setTo($to) 
      ->setSubject('Password reminder...') 
      ->setBody($this->getPartial('resetPasswordEmail', array(
       'newPassword' => $newPassword)), 'text/html'); 
     $sendResult = $this->getMailer()->send($message); 
    } 
    catch(Exception $e){/*Do nothing*/} 
} 
while($sendResult !== 1); 

接下来,我将添加一些配置设置来限制重试次数。

2

听起来像一个SMTP问题。

如果您尝试从命令行下面会发生什么:

telnet splodge.loc 25

可以连接?答复线是否以220开头?

如果没有,那么你的SMTP服务器(或者也许是防火墙)配置有问题。

+0

使用telnet时,我每次都得到:[220 localhost ESMTP]。代码有时会发送,有时不会。这真的很奇怪。 – 2010-06-16 09:11:40

0

我只是想添加到此。对我来说,问题是当我的smtp服务器重新启动时,dovecot没有回来。只要我开始鸽舍,一切都很好。所以最后它是一个smtp问题,所以如果其他人有这个问题,你几乎可以肯定这是一个smtp问题。

相关问题