开发者

Need help with Swift mailer with Kohana wrapper

开发者 https://www.devze.com 2022-12-23 04:54 出处:网络
My current code is this $swift = email::connect(); $swift->setSubject(\'hello\') ->setFrom(array(\'alex@example.com.au\' => \'Alex\'))

My current code is this

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

The email::connect() returns an instance of SwiftMailer.

As per these docs, it would seem that it should work.

However, I get an error

Fatal error: Call to undefined method Swift_Mailer::setSubject() in /home/user/public_html/application/classes/controller/properties.php  on line 45

I've seen that email::connect() does exactly what the example code in the docs does. That is

  • include the correct file
  • return an instance of the library

What am I doing wrong?

Thanks


You're using a Swift_Mailer instance, not a Swift_Message like in the example you linked to.

I think you want something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号