尝试在类“Swift_Mailer”上调用方法“sendEmailMessage”

时间:2016-03-07 19:26:56

标签: php frameworks

我正在尝试使用swiftmailer发送电子邮件。 我的邮件课程:

 <?php


namespace Src\EmailBundle\Services;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Mailer\MailerInterface;

class MailerHelper implements MailerInterface
{
public $mailer;

public function __construct($mailer)
{
    $this->mailer = $mailer;
}

/**
 * @param string $subject
 * @param string $fromEmail
 * @param string $toEmail
 * @param string $body
 */
public function sendEmailMessage($subject, $fromEmail, $toEmail,$body)
{
    $message = \Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom($fromEmail)
        ->setTo($toEmail)
        ->setBody($body);

    $this->mailer->send($message);
}

}

我的config.yml

mailer_helper :
    class:    Src\EmailBundle\Services\MailerHelper
    arguments: ['@mailer']

在我的控制器中:

$this->get('MailerHelper')->sendEmailMessage('test','test@gmail.com','test2@gmail.com',"Test");

现在我收到了这个错误:

Attempted to load class "MailerHelper" from namespace "Src\EmailBundle\Services" 
 Do you need to "use" it from another namespace?

我觉得服务有误,但我不确定。 非常感谢您提前提供任何帮助。

0 个答案:

没有答案