English 中文(简体)
Why is SwiftMailer throwing "Internal Server Error"?
原标题:

I am using Symfony + SwiftMailer and getting the following error from SwiftMailer:

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

and can t figure out why. I am using hMailServer on my local machine, and have setup my factories.yml file (as I m using Symfony) as follows:

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

I m using the following code to send:

$message = $this->getMailer()->compose(
     noreply@splodge.loc ,
     info@splodge.loc ,
     Reset Password , 
     Message 
);
$result = $this->getMailer()->send($message);

Has anyone had an issue like this before?

I have found that sometimes, and very randomly, the send goes through, but every other time, I get the above error message. So constantly refreshing the page that sends the mail, fails unpredictably, and as the code sometimes works, it s kinda hard to figure out what s wrong.

Any help will be highly appreciated!


Further investigation has shown that the SMTP server does send [220 localhost ESMTP], but after taking a look at hMailServer logs, I discovered the following:

"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"

Could it be that SwiftMailer is HELO/EHLOing too early, and that this is simply a time issue? Can I delay the HELO transmission a bit?

The good logs, when the thing actually sends looks as follows:

"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"

So it has to be to do with the HELO/EHLO acknowledgement. Please advise! :)

最佳回答

Managed to get this working by creating a loop that retries the mail sending...

$sendResult = false;
do
{
    try
    {
        $message = Swift_Message::newInstance()
            ->setFrom( noreply@splodge.loc ,  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);

Next I ll add some config settings to limit the number of retries.

问题回答

Sounds like an SMTP issue.

What happens if you try the following from the command-line:

telnet splodge.loc 25

Can you connect? Does the reply line start with 220?

If not, then you ve got a problem with your SMTP server (or perhaps firewall) config.

i just wanted to add onto this. for me the issue was when my smtp server reboot, dovecot didn t come back up. as soon as i started dovecot, everything was fine. so in the end it was an smtp issue so if anyone else has this issue you can pretty much be sure it s an smtp issue.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签