2016-11-05 161 views
0

我想通过使用Symfony 3.1和SwiftMailer发送测试邮件,但它不起作用。我正在阅读其他解决方案,但仍然无法正常工作。Symfony 3.1 swiftmailer电子邮件不发送

Config.yml:

swiftmailer: 
    transport: %mailer_transport% 
    encryption: %mailer_encryption% 
    auth_mode: %mailer_auth_mode% 
    host:  %mailer_host% 
    username: %mailer_user% 
    password: %mailer_password% 
    spool:  { type: memory } 

Parameters.yml

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

Parameters.yml第2节我尝试:

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

控制器:

public function contactAction(Request $request) 
    { 
     $name = $request->request->get('name'); 
     $surname = $request->request->get('surname'); 
     $email = $request->request->get('email'); 
     $subject = $request->request->get('subject'); 
     $message = $request->request->get('message'); 
     $data = ""; 
     if($request->request->get('contact_submit')){ 

      $message = \Swift_Message::newInstance() 
       ->setSubject($subject) 
       ->setFrom($email) 
       ->setTo('[email protected]') 
       ->setBody($message); 

      $this->get('mailer')->send($message); 

      $data = "Thank you: $name"; 

     } 
     return $this->render('przedszkole/contact.html.twig', array('data' => $data));  
    } 

所以点击提交后,我的看法改变,让我看看:谢谢$名字,但我没有得到任何电子邮件:/

我改变我的Gmail电子邮件的安全拉特就像有人告诉其他解决方案,但它对我没有帮助:/

我还取消了swiftmailer:config_dev.yml中的delivery_adress。

我会感谢任何帮助:/

+0

您是否尝试过这里讨论的解决方案:http://stackoverflow.com/questions/3478906/using-phps-swiftmailer-with-gmail – LBA

+0

您使用的是哪个版本的PHP?你看到服务器日志或Symfony工具栏中的相关错误吗? –

+0

PHP 5.6.23。我不会在任何地方看到任何错误。 – Abdulos

回答

0

你怎么样用头(只)以下YML配置:

mailer_transport: gmail 
    mailer_user: [email protected] 
    mailer_password: mypass 

,我读了有你不需要的默认设置设置为Gmail,也许因为你正在设置,它有一些影响。我不确定这是否能解决问题,但您可以尝试。

+0

它没有帮助:/ – Abdulos

0

我想这个问题可能是电子邮件进入假脱机队列。我也曾与其他人见面。您可以通过显式地禁用它:

spool: 
    enabled: false 
0

我有机会来调试你的代码,我得到的是你需要改变这两条线

->setFrom($email) 
->setTo('[email protected]') 

->setFrom('[email protected]') 
->setTo($email) 

setFrom()将包含您的电子邮件ID和setTo()将具有收件人ID。

相关问题