在Symfony 2中收到类似致命错误的错误:未找到类... \ Controller \ Swift_SmtpTransport?

时间:2014-11-11 05:12:17

标签: symfony swiftmailer

I am  new to Symfony Swift mailer. I have tried the following code bellow to configure the username and password

但是加载像Swift_SmtpTransport这样的类时出现问题。

   $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)
                ->setUsername('xxxxxxxx@gmail.com')
                ->setPassword('yyyyyy');

    $mailer = Swift_Mailer::newInstance($transport);

    $message = Swift_Message::newInstance();

    $body="body-text";
    $subject="subject-text";
    $message->setSubject($subject)
        ->setFrom('xxxxxxxxx@gmail.com')
        ->setTo('zzzzzzzzz@gmail.com')
        ->setContentType('text/html')
        ->setBody($body);
    $result = $mailer->send($message);
    return $result;

提前致谢。

1 个答案:

答案 0 :(得分:2)

 $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)
                ->setUsername('xxxxxxxx@gmail.com')
                ->setPassword('yyyyyy');

    $mailer = \Swift_Mailer::newInstance($transport);

    $message = \Swift_Message::newInstance();