Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 需要使用带有Kohana包装的Swift mailer的帮助吗_Php_Email_Kohana_Kohana 3_Swiftmailer - Fatal编程技术网

Php 需要使用带有Kohana包装的Swift mailer的帮助吗

Php 需要使用带有Kohana包装的Swift mailer的帮助吗,php,email,kohana,kohana-3,swiftmailer,Php,Email,Kohana,Kohana 3,Swiftmailer,我现在的代码是 $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' => 'Alex')) ->setBody('hello')

我现在的代码是

$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();
电子邮件::connect()

根据这一点,它似乎应该起作用

然而,我得到了一个错误

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\u邮件
实例,而不是链接到的示例中的
Swift\u邮件

我想你想要这样的东西:

$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);

被周五下午晚些时候诅咒。谢谢你,朋友,周末愉快!顺便说一句,我看到你来自布里斯班,如果你住在北边100公里,我会给你买瓶啤酒:P@alex:谢谢,我实际上不喝酒(我喝的最难的可能是姜汁啤酒)。祝你周末愉快!