saji
saji

Reputation: 203

Swiftmailler in yii.?

I am trying to integrate swiftmailer in my yii application.But till now I have not succeded. I have followed the article at 'http://www.yiiframework.com/extension/swiftmailer/' and have done the following .

In Protected/Config/main.php  

    'swiftMailer' => array(
            'class' => 'ext.swiftMailer.lib.swift_required',
                    ),

In contoller Function sitecontroller.php


 $SM = Yii::app()->swiftMailer;
        $mailHost = 'mail.example.com';
        $mailPort = 25; // Optional

    // New transport
       $Transport = $SM->smtpTransport($mailHost, $mailPort);
       $Mailer = $SM->mailer($Transport);


        $Message = $SM
        ->newMessage('My subject')
        ->setFrom(array('[email protected]' => 'Hello'))
        ->setTo(array('[email protected]' => 'Recipient Name'))
        ->addPart($content, 'text/html')
        ->setBody($plainTextContent);

    // Send mail
    $result = $Mailer->send($Message);

And now itsshowing error:

 include(swift_required.php): failed to open stream: No such file or directory

Upvotes: 0

Views: 1055

Answers (1)

Andreas
Andreas

Reputation: 5335

The article states:

'swiftMailer' => array(
'class' => 'ext.swiftMailer.SwiftMailer',

),

and NOT

 'swiftMailer' => array(
            'class' => 'ext.swiftMailer.lib.swift_required',
                    ),

You need to specify the class name assuming you have extracted and moved the swiftMailer folder to protected/extensions

EDIT

The instructions above are valid when you download the yii extension only. If you wish to download swiftmailer from swiftmailer.org then you can do the following:

  1. download swiftmailer from swiftmailer.org
  2. extract it in your vendors folder (protected/vendor/)
  3. place the the following code in the file where you need to call swiftmailer
require_once('swift/lib/classes/Swift.php');
Yii::registerAutoloader(array('Swift','autoload'));
require_once('swift/lib/swift_init.php');

Make sure you have the vendor folder in your imports Yii::import('application.vendor.*');

Upvotes: 2

Related Questions