What am I missing?
services.yml
AppBundle\Services\ItemAddService:
arguments: ['@mailer']
ItemAddService class
namespace AppBundle\Services;
class ItemAddService{
private $mymailer;
public function __construct(\Swift_Mailer $mailer){
$this->mymailer = $mailer;
}
public function itemCreatedMailer(){
$message = (new \Swift_Message('Hello Email'))
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody("Successfully got SwiftMailer to mail from Symfony3");
$this->mymailer->send($message);
return "Check mail";
}
}
When I call itemCreateMailer() in the controller I get this
"Type error: Argument 1 passed to AppBundle\Services\ItemAddService::__construct() must be an instance of SwiftMailer, none given, called in /home/admin-daniel/symfony-test-sites/july132017/src/AppBundle/Controller/DefaultController.php"
Missing something....
Try this in services.yml
AppBundle\Services\ItemAddService: arguments: $mailer: '@mailer'