Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

symfony - Configure Symfony2/Swiftmailer to use "sendmail -t"

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: ~

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.

How do I tell Swiftmailer to use sendmail -t (preferrably via configuration)?

Edit 2: For now, I'm using

$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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just spent the day on this very issue.

I prefer using straight configuration for this kind of thing, and I found this to work:

# app/config/services.yml
services:
  swiftmailer.mailer.default.transport:
    class:     Swift_SendmailTransport
    arguments: ['/usr/sbin/sendmail -t']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...