YiiMail, where do I enter input password, smtp?

Dear you,

I am trying to send my first email using yii framework extension yiiMail (http://www.yiiframew…extension/mail/)

It seems the document is not very detailed (many steps are skipped, which is killing newbies like me!). I configured the following in main.php


'import'=>array(

		'application.models.*',

		'application.components.*',

            	'ext.mail.YiiMailMessage',

	),


            	'mail'=> array(

                		'class' => 'ext.mail.YiiMail',

 			'transportType' => 'php',

 			'viewPath' => 'application.views.mail',

 			'logging' => true,

 			'dryRun' => false

            	),

Here is the code in controller to send email:


    	public function ActiontestEmail () 

    	{

        	$message = new YiiMailMessage;

        	$message->setBody('Message content ', 'text/html');

        	$message->subject = 'subject ';

        	$message->addTo('xu.shenxin@gmail.com');

        	$message->from = Yii::app()->params['admin33Email'];

        	Yii::app()->mail->send($message);

        	


    	}

I am using this url to run this action: http://localhost/vs/…=user/testemail

The result is a white screen. nothing is sent. Where do I input password, or smtp server? what I should do step by step to make it work?

Thank you!





	'mail' => array(

		   'class' => 'ext.yii-mail.YiiMail',


		   'transportType' => 'smtp',

		   'transportOptions'=>array(

		          'host'=>'smtp.host.xy',

		          //'encryption'=>'tls',

		          'username'=>'user',

		          'password'=>'password',

		          'port'=>25,

		    ),


		    'viewPath' => 'application.views.mail',

		    'logging' => true,

		    'dryRun' => false

		 ),




thanks!

Let me try that. Can you tell me what is the different between php and smtp for transportOptions? or point me to a source to find out.

transportType = ‘php’ uses the PHP mail() function and doesn’t connect to a smtp-server.

Thanks!

Hi!

I want to use a Gmail account as SMTP server.

When I use the same config as proposed by Joblo, I get this error :


fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:

error:1408F10B:SSL routines:func(143):reason(267) 

in : /protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/StreamBuffer.php(233)

I read this thread that says that in order to use Gmail with Swiftmailer, we should use options like :


authentication: :plain

enable_starttls_auto: true

in order to enable tls encryption only AFTER the authentication is done…

Is there a way (and how) to do that with yii-mail?

Thx

I think the issue you are having is with your server and not Yii-Mail. If you google your error a bit more you will find that it looks like your OpenSSL is outdated or has an error.

Uncomment php_openssl.dll in your php.ini file ( I mean load php_openssl.dll)

Regards

Yii Fan

if you use the SwiftMailer extension with a gmail account, i got it working by doing the following:

In the swift mailer class modify smtpTransport so it allows for ssl authentication as follows:


public function smtpTransport($host=null, $port=null,$ssl=null) {

     return Swift_SmtpTransport::newInstance($host, $port,$ssl);

}

then in config/main.php, add following component:


'components'=>array(

//...

     'swiftMailer' => array(

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

     ),

//...

)



and to actually send the message do the following:


$SM = Yii::app()->swiftMailer;


            // New transport

            $transport = $SM

                    ->smtpTransport('smtp.gmail.com', 465,"ssl")

                    ->setUsername('username@gmail.com')

                    ->setPassword('password');


            // Mailer

            $mailer = $SM->mailer($transport);


            // New message

            $message = $SM  ->newMessage('foo')

                            ->setFrom($array('username@gmail.com' => 'Your Name'))

                            ->setTo(array('receiver@somewhere.com'=>'Mr.Stranger's Name'))

                            ->setBody('k thnx bye!');

            $results = $mailer->send($message);

THAT’S IT!

i don’t know if something actually changed since Fedya posted his solution, but now you can just set those options into your configuration file [/protected/config/main.php]:




'mail' => array(

	'class' => 'ext.yii-mail.YiiMail',

	'transportType' => 'smtp',

	'transportOptions'=>array(

		'host'=>'smtp.gmail.com',

		'encryption'=>'ssl',

		'username'=>'user@gmail.com',

		'password'=>'password',

		'port'=>465,

	),

	'viewPath' => 'application.views.mail',

	'logging' => true,

	'dryRun' => false

),



There is an error

array should not be $array in the code block…cost me 30 minutes of sorting out what the heck was wrong.

Thanks it was very helpful in general!