Symfony3 Swiftmailer不在生产中发送电子邮件

时间:2016-07-08 17:41:49

标签: symfony swiftmailer

当我在本地服务器上测试我的代码时,正在发送电子邮件。但是,当我在实际服务器上部署它时,不会发送电子邮件。我已取消激活“安全应用”功能。来自谷歌。我该如何发送电子邮件? 顺便说一下,每当我删除假脱机选项时,都会得到500内部服务器错误。我不需要假脱机,但似乎无法摆脱它。 提前谢谢!

这是我的控制器

    public function contactAction(Request $request) {
       $enquiry = new Enquiry();
       $form = $this->createForm(EnquiryType::class, $enquiry); 
       $form->handleRequest($request);

      if($request->getMethod() == "POST") {
        // Send email
        $name = $form["name"]->getData();
        $email = $form["email"]->getData(); 
        $subject = $form["subject"]->getData();  
        $body = $form["body"]->getData();                  
         // Send message
         $message = \Swift_Message::newInstance()
                    ->setSubject($subject)
                    ->setFrom($email)
                    ->setTo('myEmail@gmail.com')
                    ->setBody($this->renderView('Emails/emailTemp.html.twig', array(
                        'name' => $name,
                        'email' => $email,
                        'subject' => $subject,
                        'body' => $body,

                        )
                    ))

        ;

                $this->get('mailer')->send($message);
                $this->addFlash(
                    'notice',
                    'Email has been sent!'
                );
                return $this->redirectToRoute('contactme');            


    }

config.yml

# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host:      "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }

parameters.yml

mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: myemail@gmail.com
mailer_password: MyPasWd

0 个答案:

没有答案