繁体   English   中英

在symfony中使用swiftmailer发送电子邮件

[英]send email with swiftmailer in symfony

我正在使用symfony开发该应用程序。我已经使用swiftmailer发送电子邮件了,但是没有收到邮件。 我不知道我在哪里错。 这是我的代码:

$message = \Swift_Message::newInstance()
                    ->setSubject('Password Reset')
                    ->setFrom('support@bwcmultimedia.com')
                    ->setTo('karank@ocodewire.com')
                    ->setBody($this->renderView('DRPRegistrarGeneralBundle:Email:k.txt.twig'));
                $mailStatus = $this->get('mailer')->send($message);

我已经设置了parameters.yml文件:

 database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_name: database
    database_user: user
    database_password: pass
    mailer_transport: smtp
    mailer_encryption: 
    mailer_auth_mode: "login"
    mailer_host: smtp.gmail.com
    mailer_port: 25
    mailer_user: karansofat89@gmail.com
    mailer_password: pass
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt

配置文件:

swiftmailer:
    transport: %mailer_transport%
    encryption: tls
    auth_mode: login
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%

请帮忙

要通过gmail发送电子邮件,您可以将mailer_transport设置为gmail并省略端口。

parameters.yml

mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: karansofat89@gmail.com
mailer_password: pass

配置文件

swiftmailer:
    transport:  %mailer_transport%
    encryption: %mailer_encryption%
    auth_mode:  %mailer_auth_mode%
    host:       %mailer_host%
    username:   %mailer_user%
    password:   %mailer_password%

您还应该确保已启用openssl扩展名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM