【问题标题】:Email is not Receiving through Swift Mailer Symfony2电子邮件未通过 Swift Mailer Symfony2 接收
【发布时间】:2017-12-13 22:58:52
【问题描述】:
  • 我尝试通过 swiftmailer 发送电子邮件

  • 回复代码 200 正常,但仍未收到电子邮件。

控制器代码

 public function EmaiAction(Request $request)
 {
    $mailer = $this->get('mailer');

    $logger = new \Swift_Plugins_Loggers_ArrayLogger();
    $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));


    $message = \Swift_Message::newInstance()
    ->setSubject('Hello')
    ->setFrom('mohd@abc.com')
    ->setTo('***@gmail.com')
    ->setBody('This is a test email.');

    if ($this->get('mailer')->send($message)) {
    echo '[SWIFTMAILER] sent email to ';
    } else {
    echo '[SWIFTMAILER] not sending email: ' . $mailer->dump();
    }    

die("email send");

}

输出

   [SWIFTMAILER] sent email to

config.yml

swiftmailer:
disable_delivery:  true
transport: smtp
encryption: ssl
port:   465
auth_mode: login
host:      smtp.gmail.com
username:  ***@gmail.com
password:  passwrd
delivery_address: abc@gmail.com
  • 在 if/else 中执行 echo 时,如果条件为真,则表示其为真。

  • 那为什么我收不到邮件。

  • 发送邮件时不显示错误日志

  • 我使用 cpanel 应用是生产环境。

【问题讨论】:

  • 您是否提供了有效的往返电子邮件地址?
  • 是的,我已经给出了正确的往返
  • “允许不太安全的应用访问您的帐户”- 您是否为 gmail 启用了此功能?
  • 是的,我做到了,gmail ->设置也允许 imap 启用
  • 尝试添加您的代码-$this->get('mailer')->send($message);。不在 if 条件下。

标签: php symfony email


【解决方案1】:
disable_delivery:  true

这会禁用用于开发的邮件发送(请参阅Docs

另外尝试像这样的 swiftmailer 配置

swiftmailer:
    transport: gmail
    username:  ***@gmail.com
    password:  passwrd

【讨论】:

  • 当我删除 disable_delivery 时无法与主机 smtp.gmail.com 建立连接 [连接被拒绝 #111]
  • 尝试将传输更改为 gmail (symfony.com/doc/current/email/gmail.html)
  • 仍然面临同样的问题
  • 查看更新的答案。如果您对 gmail 使用 2FA,则需要执行其他步骤。请参阅文档。
  • 我也试过这个配置,但它仍然对我不起作用
【解决方案2】:
$message = \Swift_Message::newInstance()
->setSubject('Hello')
->setFrom('mohd@abc.com')
->setTo('***@gmail.com')
->setBody('This is a test email.');
$this->get('mailer')->send($message);

【讨论】:

  • 现在尝试同样的事情我无法与主机 smtp.gmail.com 建立连接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-30
  • 1970-01-01
相关资源
最近更新 更多