电子邮件不是通过Swift Mailer Symfony2接收的

时间:2017-07-10 09:17:06

标签: php symfony email

  • 我试图通过swiftmailer发送电子邮件

  • 响应代码200 ok,但仍未收到任何电子邮件。

控制器代码

 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 app是生产环境。

2 个答案:

答案 0 :(得分:0)

disable_delivery:  true

这会禁用发送邮件(参见Docs

另外尝试像这样的swiftmailer配置

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

答案 1 :(得分:0)

$message = \Swift_Message::newInstance()
->setSubject('Hello')
->setFrom('mohd@abc.com')
->setTo('***@gmail.com')
->setBody('This is a test email.');
$this->get('mailer')->send($message);
相关问题