发送电子邮件symfony swiftmailer


send email symfony swiftmailer

我正在尝试通过swiftmailer和gmail发送电子邮件。

我已经输入了我的配置yml:

swiftmailer:
    transport: gmail
    username:  xxx@gmail.com
    password:  xxx

如果我在localhost中使用它,将它们放在config_dev.yml中,它可以正常工作,如果我在本地主机中使用它但使用prod版本,它可以工作,但如果我在服务器中使用我的prod版本则不工作。

有人知道为什么?

Thnaks向致以最良好的问候

parameters.yml中是否设置了正确的参数?像这样:

# app/config/parameters.yml
parameters:
    # ...
    mailer_transport: gmail
    mailer_host:      ~
    mailer_user:      your_gmail_username
    mailer_password:  your_gmail_password

此外,你可以尝试拦截电子邮件(我认为这只能在开发中完成),看看当你尝试发送邮件时会发生什么:

# app/config/config_dev.yml
web_profiler:
    intercept_redirects: true

你也可以尝试注册一个免费的mandrill帐户(https://mandrill.com/)并在parameters.yml中使用您的mandrill smtp设置,然后检查是否有效。

有可能你有一个主机,如果你想在主机中发送电子邮件你可以用php函数mail():

$to      = 'email@domain.com';
$subject   = 'subject';
$msg       = 'Hi';
$others     = 'From: contact@domain.com' ."'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $msg, $others);