无法在 Symfony 1.4 中使用 SwiftMailer 访问附加方法

Cannot Access Attach Method using SwiftMailer in Symfony 1.4

我正在尝试使用 SwiftMailer 附加文​​件,但是当我调用 ->attach() 方法时,我得到:在 swift_mime_message

中找不到附加方法

目前,邮件已发送,但没有附件。

控制器代码如下:

$transport = Swift_MailTransport::newInstance('smtp.gmail.com', 587, 'ssl')
    ->setUsername('project@notworking.com')
    ->setPassword('Work_Pls')
;

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

$html = $this->getPartial("email/confirmation", $model);
$subject = "Order Confirmation";

// Create the message
$message = Swift_Message::newInstance();

// Give the message a subject
$message->setSubject($subject);

// Set the From address with an associative array
$message->setFrom(array('admin@derp.com' => 'Portal Noreply'));

// Set the To addresses with an associative array
$message->setTo(array('derp@gmail.com'));

// Give it a body
$message->setBody($html);

// Optionally add any attachments
$message->attach(Swift_Attachment::fromPath('uploads/important.jpg'));

// Send the message
$mailer->send($message);

我通过使用不同的邮寄方式解决了这个问题。我把邮件参数放在 factories.yml 中,它看起来像这样:

mailer:
  class: sfMailer
  param:
    logging:           %SF_LOGGING_ENABLED%
    charset:           %SF_CHARSET%
    transport:
      class: Swift_SmtpTransport
      param:
        host:       smtp.gmail.com
        port:       587
        encryption: tls
        username:   goober@gmail.com
        password:   derpderp

然后我将我的控制器更改为:

// Send email
$html = $this->getPartial("email/order_confirmation", $model);
$subject = "Order Confirmation";
$to = $derp->getUser()->getEmail();

$message = $this->getMailer()->compose(
    array('admin@derp.com' => 'Portal Noreply'),
    $to, $subject);
$message->setBody($html, 'text/html');
$message->attach(Swift_Attachment::fromPath('/projects/derp.jpg'));
 $sent_count = $this->getMailer()->send($message);