【问题标题】:symfony2 errors on sending email发送电子邮件时出现 symfony2 错误
【发布时间】:2013-11-24 11:59:02
【问题描述】:

我正在 Symfony2 中开发一个应用程序 我有一个将在 crontab 中运行的命令

这是命令:

<?php
namespace project\projBundle\Service;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Templating\EngineInterface;
class Sender {
    protected $em;
    protected $templating;
    protected $mailer;
    public function __construct($em, $templating,\Swift_Mailer $mailer) {
        $this->em = $em;
        $this->templating = $templating;
        $this->mailer = $mailer; }

    public function runSender() {
        $proj = $this->em->createQuery("query")->setMaxResults(20)->getResult();
        $message = \Swift_Message::newInstance()
            ->setSubject('Contact enquiry from symblog')
            ->setFrom('...@gmail.com')
            ->setTo('...@gmail.com')
            ->setBody($this->templating->render('projectprojBundle:Others:emailNew.html.twig', array('proj' => $proj)));

        $this->mailer->send($message); } }

parameters.yml:

parameters:
    mailer_transport: gmail
    mailer_host: ~
    mailer_user: ...@gmail.com
    mailer_password: ...

在配置测试中:

swiftmailer:
disable_delivery: false
spool: { type: memory }

这是向我发送电子邮件,但我收到了 2 封电子邮件: 第一个:

Delivery to the following recipient failed permanently:

     ...@gmail

Technical details of permanent failure:
DNS Error: Domain name not found

第二个是树枝代码,没有渲染。

我做错了什么?

【问题讨论】:

  • 似乎gmail 之后的.com 缺少一位收件人。

标签: symfony mailer


【解决方案1】:

你是否在 config.yml 中添加了这个:

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%

【讨论】:

  • 是的,它正在发送电子邮件,但我收到了一封来自 Mail Delivery Subsystem 和其他我想要但未呈现的电子邮件
  • 尝试在显示中使用$this->renderView()方法
【解决方案2】:

我用那个来修树枝:

protected $twig;
    protected $mailer;
    public function __construct(\Twig_Environment $twig,\Swift_Mailer $mailer) {
        $this->twig = $twig;
        $this->mailer = $mailer;
    }

但现在的问题是我还有html标签。

【讨论】:

猜你喜欢
  • 2014-06-07
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多