配置 Symfony2/Swiftmailer 以使用“sendmail -t"; [英] Configure Symfony2/Swiftmailer to use "sendmail -t"
问题描述
我目前正在尝试让 Symfony2/Swiftmailer 通过邮件发送已提交表单的内容.我的 parameters.yml 包含以下内容:
I'm currently trying to get Symfony2/Swiftmailer to send the contents of a submitted form via mail. My parameters.yml contains the following:
mailer_transport: sendmail
mailer_host: ~
mailer_user: ~
mailer_password: ~
由于我服务器上的 sendmail 版本不支持 -bs
选项,Swiftmailer 似乎默认使用该选项,我必须找到一种方法告诉 Symfony2/Swiftmailer 使用 sendmail-t
代替.Swift_Transport_SendmailTransport
似乎支持这一点,但 SwiftmailerBundle 似乎没有相应的配置选项.
Since the sendmail version on my server does not support the -bs
option, which Swiftmailer seems to use by default, I have to find a way to tell Symfony2/Swiftmailer to use sendmail -t
instead. Swift_Transport_SendmailTransport
seems to support that, but there doesn't seem to be a corresponding configuration option for SwiftmailerBundle.
我如何告诉 Swiftmailer 使用 sendmail -t
(最好通过配置)?
How do I tell Swiftmailer to use sendmail -t
(preferrably via configuration)?
编辑 2:现在,我正在使用
$message = \Swift_Message::newInstance()
[…];
$transport = $this->get('swiftmailer.mailer.default.transport.real');
if ($transport instanceof \Swift_Transport_SendmailTransport) {
$transport->setCommand('/usr/sbin/sendmail -t');
}
$this->get('mailer')->send($message);
我仍然想知道是否有更好的方法来做到这一点.
I'm still wondering if there's a better way to do this, though.
推荐答案
我一直在寻找和你一样的东西,我发现现在有一个 SendMailTransport 类.
I was looking for the same thing as you and i found that there is now a SendMailTransport class.
这里是文档:http://swiftmailer.org/docs/sending.html#using-the-sendmail-transport
这篇关于配置 Symfony2/Swiftmailer 以使用“sendmail -t";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!