【发布时间】:2015-06-04 22:31:13
【问题描述】:
我正在尝试使用 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);
【问题讨论】:
-
那是确切的消息吗?未找到附加方法?没有关于在非对象等上找不到的任何东西?只需要确定抱歉:p
-
"method attach not found in swift_mime_message" 是我得到的确切消息
-
我还看到
->attach()不存在于 Swift_Mime_Message 接口中。不知道为什么,或者下一步该做什么。 -
你能不能
var_dump($message);newInstance行之后,attach 行之前提供输出。我觉得奇怪的是,理论上你得到了一个Swift_Message的实例,但在attach,你有一个Swift_Mime_Message对象。 -
感谢这些 cmets。虽然我使用了不同的方法,但它们帮助我解决了这个问题。
标签: php symfony symfony-1.4 swiftmailer