5

我目前正在尝试让 Symfony2/Swiftmailer 通过邮件发送提交表单的内容。我的 parameters.yml 包含以下内容:

mailer_transport: sendmail
mailer_host: ~
mailer_user: ~
mailer_password: ~

由于我服务器上的 sendmail 版本不支持-bsSwiftmailer 似乎默认使用的选项,因此我必须找到一种方法来告诉 Symfony2/Swiftmailer 改为使用该选项sendmail -tSwift_Transport_SendmailTransport似乎支持这一点,但 SwiftmailerBundle 似乎没有相应的配置选项。

我如何告诉 Swiftmailer 使用sendmail -t(最好通过配置)?

编辑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);

不过,我仍然想知道是否有更好的方法来做到这一点。

4

3 回答 3

9

刚刚在这个问题上度过了一天。

我更喜欢对这种事情使用直接配置,我发现这很有效:

# app/config/services.yml
services:
  swiftmailer.mailer.default.transport:
    class:     Swift_SendmailTransport
    arguments: ['/usr/sbin/sendmail -t']
于 2015-11-19T22:20:40.853 回答
7

此配置应该可以工作。

mailer_transport: sendmail
mailer_host: /usr/bin/sendmail # wherever your mail is
#mailer_user: ~
#mailer_password: ~

如果还有问题,

A. check who are sending mail to someone@wxy.com
    1. console - check your permission to access sendmail
    2. web - check web user like wwww-data can access sendmail
B. check your mail log  /var/log/maillog
    When Symfony Swiftmailer send,
    1. mail log has not been processed, then PHP side problem.
    2. else if: send to outlook
        it is TLS handshake problem, it might be from outlook tls handshake.
        FYI, sendmail TLS is not working with outlook well.

        add next line to /etc/mail/access 
        Try_TLS:wxy.com              NO
    3. else:
       Sorry, google with mail log error messages again .
于 2015-04-08T06:46:25.937 回答
2

我一直在寻找和你一样的东西,我发现现在有一个 SendMailTransport 类。

这是文档:http ://swiftmailer.org/docs/sending.html#using-the-sendmail-transport

于 2014-06-15T15:24:26.730 回答