如何运行邮件功能?
How to run the email function?
public function email($name, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('send@example.com')
->setTo('my.email@example.com')
->setBody(
$this->renderView(
// templates/emails/registration.html.twig
':emails:task.twig',
['name' => $name]
),
'text/html'
)
;
$mailer->send($message);
return $this->render(':emails:task.twig');
}
我刚刚从 https://symfony.com/doc/current/email.html 复制了该代码并做了一些改动。
我想运行那个函数但是我不明白的是,第二个参数是什么?我在我的服务中使用这个功能 class.
// class or controller registered in DI container
class InvoiceMailer
{
private $mailer;
public function __construct(\Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}
private function email($name, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('send@example.com')
->setTo('my.email@example.com')
->setBody(
$this->renderView(
// templates/emails/registration.html.twig
':emails:task.twig',
['name' => $name]
),
'text/html'
);
$mailer->send($message);
}
public function SendEmail($name)
{
$this->email($name, $this->mailer);
}
}
public function email($name, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('send@example.com')
->setTo('my.email@example.com')
->setBody(
$this->renderView(
// templates/emails/registration.html.twig
':emails:task.twig',
['name' => $name]
),
'text/html'
)
;
$mailer->send($message);
return $this->render(':emails:task.twig');
}
我刚刚从 https://symfony.com/doc/current/email.html 复制了该代码并做了一些改动。
我想运行那个函数但是我不明白的是,第二个参数是什么?我在我的服务中使用这个功能 class.
// class or controller registered in DI container
class InvoiceMailer
{
private $mailer;
public function __construct(\Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}
private function email($name, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('send@example.com')
->setTo('my.email@example.com')
->setBody(
$this->renderView(
// templates/emails/registration.html.twig
':emails:task.twig',
['name' => $name]
),
'text/html'
);
$mailer->send($message);
}
public function SendEmail($name)
{
$this->email($name, $this->mailer);
}
}