需要使用 Kohana 包装器的 Swift 邮件程序帮助
-
21-09-2019 - |
题
我当前的代码是这样的
$swift = email::connect();
$swift->setSubject('hello')
->setFrom(array('alex@example.com.au' => 'Alex'))
->setTo(array('alex@example.com.au' => 'Alex'))
->setBody('hello')
->attach(Swift_Attachment::fromPath(DOCROOT . 'assets/attachments/instructions.pdf'));
$swift->send();
这 email::connect()
返回 SwiftMailer 的实例.
按照 这些文档, ,看起来应该可行。
但是,我收到错误
Fatal error: Call to undefined method Swift_Mailer::setSubject() in /home/user/public_html/application/classes/controller/properties.php on line 45
我见过那个 email::connect()
与文档中的示例代码完全相同。那是
- 包含正确的文件
- 返回库的实例
我究竟做错了什么?
谢谢
解决方案
您正在使用一个 Swift_Mailer
实例,不是 Swift_Message
就像您链接到的示例一样。
我想你想要这样的东西:
$swift = email::connect();
$message = Swift_Message::newInstance();
$message->setSubject('hello')
->setFrom(array('alex@example.com.au' => 'Alex'))
->setTo(array('alex@example.com.au' => 'Alex'))
->setBody('hello')
->attach(Swift_Attachment::fromPath(DOCROOT . 'assets/attachments/instructions.pdf'));
$swift->send($message);
不隶属于 StackOverflow