Andresch Serj
Andresch Serj

Reputation: 37438

Control Sendmail with Swiftmailer in Symfony

The following Code works on the server i am using (Hosteurope WebPack):

mail('[email protected]', 'some subject', 'sendmail is working', 'From: [email protected]', "");

The following Code isn't:

$message = \Swift_Message::newInstance()
  ->setSubject('some subject')
  ->setFrom('[email protected]')
  ->setTo('[email protected]')
  ->setBody('sendmail via swiftmail is working');
$mailer = $this->get('mailer');
$logger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
$mailer->send($message);

And in $logger writes this error:

++ Starting Swift_Transport_SendmailTransport
<< 
!! Expected response code 220 but got code "", with message "" (code: 0)"
  ...

My configuration is:

swiftmailer:
    transport: "sendmail"
    sender_address: "[email protected]"

I do not see why one is working and the other isn't since, as far as i can tell, the call should be identical.

Upvotes: 0

Views: 1663

Answers (2)

mattxtlm
mattxtlm

Reputation: 128

If your are using sendmail with symfony, it may happen that you have to pass some additional options. For example:

'/usr/sbin/sendmail -t -i'

To find out which options must be passed, create a phpinfo.php on your server,

<?php
phpinfo();
>

run it and find the entries which start with:

sendmail_from
sendmail_path

Either of them will show /usr/sbin/sendmail -some_options

In order to get it working in symfony, you can't paste it in the config.yml directly - at least in my experience.

Open up services.yml and add:

swiftmailer.mailer.default.transport:
  class:     Swift_SendmailTransport
  arguments: ['/usr/sbin/sendmail -t -i']

Where arguments is the path from the php entry from above.

Then set config.yml to:

swiftmailer:
    transport: sendmail

Or, if you like to separate dev and prod env, paste it in one of them.

Upvotes: 1

Andresch Serj
Andresch Serj

Reputation: 37438

The problem is that the Sendmail Transport does not send the From Header (as expected). Using "mail" as the transport worked for me:

swiftmailer:
    transport: "sendmail"
    sender_address: "[email protected]"

Hope this might help others having trouble with Hosteurope and sendmail/sending mails.

Upvotes: 0

Related Questions