Swiftmailer Caught exception: Expected response code 250 but got code "", with message ""

woj_jas picture woj_jas · Oct 10, 2014 · Viewed 11.5k times · Source

I'm having trouble in symfony 1.4 swiftmailer . When I try to use sendmail function() I got error code :

Caught exception: Expected response code 250 but got code "", with message ""

And symfony doesn't send messages.

Below is my function sendmail

static function sendmail($mail, $textmessage, $subject) {
    try {
        $message = Swift_Message::newInstance()
                ->setFrom(sfConfig::get('app_mail_address_from'))
                ->setTo($mail)
                ->setSubject($subject)
                ->setBody($textmessage)
                ->setContentType("text/html");
      //  sfContext::getInstance()->getMailer()->send($message);
      sfContext::getInstance()->getMailer()->send($message);
    //   mail("mymailcom", "A subject", "A message", "FROM: [email protected]");

    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }


}

What I tried to do:

  1. I tried to test mail() function. It works good.

  2. I tried to change smtp settings to gmail account - not working

My Server is: CentOs6 on godaddy.co.uk server

Can somebody please help me with this error ?

Answer

woj_jas picture woj_jas · Oct 10, 2014

Ok , post from comment helped, maybe somebody will use that: I think the problem is swiftmailer:

 try {

        $transport = Swift_MailTransport::newInstance();
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance('Subject')
            ->setFrom(sfConfig::get('app_mail_address_from'))
            ->setTo($mail)
            ->setSubject($subject)
            ->setBody($textmessage)
            ->setContentType("text/html");
        $mailer->send($message);
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";die;
    }

This is working code