This class is now much more flexible as you have separated the choice of
transport out of the implementation and into the container.

Which mail transport you have chosen may be something other services need
to know about. You can avoid having to change it in multiple places by making
it a parameter in the container and then referring to this parameter for
the Mailer service's constructor argument:

When defining the newsletter_manager service, the mailer service does
not exist yet. Use the Reference class to tell the container to inject the
mailer service when it initializes the newsletter manager:

Whilst you can retrieve services from the container directly it is best
to minimize this. For example, in the NewsletterManager you injected
the mailer service in rather than asking for it from the container.
You could have injected the container in and retrieved the mailer service
from it but it would then be tied to this particular container making it
difficult to reuse the class elsewhere.

You will need to get a service from the container at some point but this
should be as few times as possible at the entry point to your application.

As well as setting up the services using PHP as above you can also use
configuration files. This allows you to use XML or YAML to write the definitions
for the services rather than using PHP to define the services as in the
above examples. In anything but the smallest applications it makes sense
to organize the service definitions by moving them into one or more configuration
files. To do this you also need to install
the Config component.