我需要使用来自自定义批处理功能的swiftmailer发送电子邮件,但是当我在参数中添加“ \ Swift_Mailer $ mailer”时,出现此错误:“函数App \ Controller \ ContactAdminController :: batchActionMail()的参数太少,第2行在/var/www/html/cvtheque/src/Controller/ContactAdminController.php中传递了第3行,而恰好是第3行”
我以前已经配置了电子邮件的发送,我从另一个功能发送电子邮件,并且效果很好。看来,问题出在以下事实:此功能在管理员奏鸣曲类的自定义CRUDCONTROLLER中
/**
* @param ProxyQueryInterface $selectedModelQuery
* @param Request $request
* @return RedirectResponse
*/
public function batchActionMail(ProxyQueryInterface $selectedModelQuery, Request $request = null, \Swift_Mailer $mailer)
{
$this->admin->checkAccess('edit');
$this->admin->checkAccess('delete');
$modelManager = $this->admin->getModelManager();
$target = $modelManager->find($this->admin->getClass(), $request->get('targetId'));
$id = $request->get('idx');
$conn = $this->get('doctrine.dbal.default_connection');
$typedemail = $_POST['typemail'];
if ($typedemail == 'decline') {
$type = 'décliné';
$infomail = $conn->query("SELECT * FROM MAILS WHERE nom = '$type' ");
$infomail = $infomail->fetch();
$sujet = $infomail['sujet'];
$contenu = $infomail['contenu'];
foreach ($id as $person) {
$email = $conn->query("SELECT email FROM CONTACT WHERE id = '$person'");
$email = $email->fetch();
$email = $email['email'];
$mail = (new \Swift_Message($sujet))
->setFrom('anaddress@email.fr')
->setTo($email)
->setBody($contenu);
$mailer->send($mail);
我尝试添加:
$transport = (new \Swift_SmtpTransport('smtp@gmail.com', 465, 'ssl'))
->setUsername('ronaldmcdo85@gmail.com')
->setPassword('xxxxxx');
$mailer = new \Swift_Mailer($transport);
在$ mail =之前... 但是它仍然不起作用
此功能必须允许从一个地址向一个或多个选定地址发送一封或多封电子邮件