2017-01-30 104 views
0

我想使用symfony发送电子邮件,但swiftmailer不发送任何电子邮件。我甚至没有得到错误报告或其他任何东西。这就是我的代码:swiftmailer不发送电子邮件

$mail = \Swift_Message::newInstance() 
       ->setSubject('Subject') 
       ->setTo('[email protected]') #this is replaced by real email of course 
       ->setFrom('[email protected]') 
       ->setBody('Testbody'); 

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

那的配置:

swiftmailer: 
default_mailer: mailer 
mailers: 
    mailer: 
     transport: "%mailer_transport%" 
     host:  "%mailer_host%" 
     username: "%mailer_user%" 
     password: "%mailer_password%" 
     #spool:  { type: memory } 

我什至主机设置为不存在的地址,但我不从swiftmailer或symfony中得到任何错误。

我试图找到的lib文件,但在symfony的任何地方的文件没有Swift_Message或的newInstance,奇怪

+1

你正在使用SM config正在使用的参数是什么?你也有一个运行邮件服务器? – stevenll

+1

你想拥有我的邮件服务器凭据吗? :)它的外部邮件服务器。例如,当我将服务器主机更改为非工作地址时,如果外部邮件工作正常,我甚至不会收到swiftmailer – Asara

+0

的任何错误,那么此处显示的代码看起来不错。你确定没有别的东西阻止你的代码发送消息吗? – stevenll

回答

0

使用此代码

$message = \Swift_Message::newInstance() 
      ->setSubject('Validation de votre commande') 
      ->setFrom('[email protected]') 
      ->setTo('[email protected]') 
      ->setBody('Testbody'); 
      ->setCharset('utf-8') 
      ->setContentType('text/html') 
      ->setBody('test'); 

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

/配置/ parametres.yml :

mailer_transport: gmail 
mailer_host: smtp.gmail.com 
mailer_user: your mail 
mailer_password: your password mail 
在app

/配置/ config.yml:

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

为什么你认为我有一个Gmail帐户? – Asara

+0

最好的解决方案是使用gmail帐户 –

+0

该评论应该是负面选票。这是非常远离解决方案 – Asara

0

我曾经见过有同样问题的人。对他来说问题在于线轴队列。它是通过明确禁止任何解决阀芯:

spool: 
     enabled:false 

或代码冲洗队列:

$this->get('mailer')->send($mail); 
$spool = $this->get('mailer')->getTransport()->getSpool(); 
$spool->flushQueue($this->get('mailer')->getTransport()); 

希望工程!

+0

,你可以看到我的问题,sppol没有激活,我甚至检查它,但没有找到邮件那里 – Asara

相关问题