Configure Symfony2/Swiftmailer to use "sendmail -t"
Asked Answered
C

3

5

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.

Camise answered 23/9, 2013 at 12:12 Comment(0)
A
2

I was looking for the same thing as you and i found that there is now a SendMailTransport class.

Here is the documentation : http://swiftmailer.org/docs/sending.html#using-the-sendmail-transport

Adelleadelpho answered 15/6, 2014 at 15:24 Comment(0)
B
9

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']
Bimanous answered 19/11, 2015 at 22:20 Comment(1)
When using the above service configuration, then there is no need to define any parameters defined in the parameters.yml and config.yml accordingly e.g. mailer_host, mailer_password, mailer_port etc.Pour
E
7

This configuration should work.

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

If there is still problem,

A. check who are sending mail to [email protected]
    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 .
Extrauterine answered 8/4, 2015 at 6:46 Comment(0)
A
2

I was looking for the same thing as you and i found that there is now a SendMailTransport class.

Here is the documentation : http://swiftmailer.org/docs/sending.html#using-the-sendmail-transport

Adelleadelpho answered 15/6, 2014 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.