2014-10-04 62 views
0

我有我的網站正在製作中,有Hostinger,並且參數和配置相同,我不能在生產中發送電子郵件,但是我可以在開發模式下。我改變了參數和配置文件與其他問題中看到的其他設置,但沒有成功。無論如何,我得到的錯誤是:在Symfony2的項目中使用Swiftmailer時出錯

連接無法與主機smtp.gmail.com 建立[連接超時#110] 500內部服務器錯誤 - Swift_TransportException

我parameters.yml文件:

parameters: 
    ... 
    mailer_transport: gmail 
    mailer_encryption: ssl 
    mailer_auth_mode: login 
    mailer_host: smtp.gmail.com 
    mailer_user: [email protected] 
    mailer_password: xxxx 
    ... 

我config.yml文件:

# Swiftmailer Configuration 
swiftmailer: 
    transport: gmail 
    host:  smtp.gmail.com 
    username: [email protected] 
    password: xxxx 

我的控制文件:

public function kontaktuaAction() 
{ 
    $kontaktua = new Kontaktua(); 
    $form = $this->createForm(new KontaktuaType(), $kontaktua); 

    $request = $this->getRequest(); 
    if ($request->getMethod() == 'POST') { 
     $form->bind($request); 

     if ($form->isValid()) { 

      $message = \Swift_Message::newInstance() 
       ->setSubject($kontaktua->getGaia()) 
       ->setTo('[email protected]') 
       ->setFrom($kontaktua->getEmaila()) 
       ->setBody($kontaktua->getIzena().'(e)k, email helbidea '.$kontaktua->getEmaila().' duena hurrengo mezu hau'. 
        ' bidali dizu: '.$kontaktua->getMezua()); 
      $this->get('mailer')->send($message); 

      return $this->redirect($this->generateUrl('kontaktua')); 
     } 
    } 

    return $this->render('TaldeaBundle:Default:kontaktua.html.twig', array(
     'form' => $form->createView() 
    )); 
} 

回答

0

以下設置爲我工作:

config.yml under swiftmailer 
    encryption: ssl 
    auth_mode: login 

parameters.yml: 
    mailer_transport: smtp 
    mailer_host: smtp.gmail.com 
    mailer_user: #gmail_user_name 
    mailer_password: #gmail_password 
+0

我都試過,但沒有結果。它在生產環境中工作嗎? – xaaleja 2014-10-05 13:26:09