Send mail through smtp.gmail.com in symfony 2 using swiftmailer

元气小坏坏 提交于 2020-01-13 10:06:14

问题


I am having a trouble of sending mail from xampp localhost using gmail. And after a long time I finally successful on it. And I am sharing it with all you. If I am wrong need proper solution for it.

in config.yml of your symfony 2 Write those

swiftmailer:
    disable_delivery:  false
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
    port:      %mailer_port%
    encryption: %mailer_encryption%

In your parameters.yml

mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: gmail_user_id_without_@gmail.com
mailer_password: Your_gmail_pass
mailer_port: 465 or 587
mailer_encryption:  ssl 

回答1:


u can try this one

Parameter.yml

mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'xxxxxxxxxxxx'

config.yml

swiftmailer:
   transport: gmail
   host:      smtp.gmail.com
   username:  'Yourmail@gmail.com'
   password:  'Password'



回答2:


You can either specify the parameters directly in the Swift mailer cofiguration or read them from parameters.ini.

Example:

In parameters.ini

mailer_transport  = smtp
mailer_host       = localhost
mailer_user       = null    
mailer_password   = null

In config.yml,

# Swiftmailer Configuration
swiftmailer:
    transport: smtp
    encryption: ssl
    auth_mode: login
    host:      smtp.gmail.com
    username:  user@xyz.com
    password:  password
    spool:
      type: file
      path: "%kernel.root_dir%/extras/spool"

Here, 'path' is the path to the directory where the spooled mails are stored.



来源:https://stackoverflow.com/questions/19086476/send-mail-through-smtp-gmail-com-in-symfony-2-using-swiftmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!