Sunday, 15 April 2012

Yii framework sending email via Gmail !!!!

Yii framework sending email via Gmail! No need smtp locally!!!!

Step 1: Download email ext. from Yii website: http://www.yiiframework.com/extension/email/, extracting and putting it under protected/extension.

e.g., protected/extension/mail/ - doc
                                                     - vendors
                                                     - YiiMail.php
                                                     - YiiMailMessage.php
                                                     
Step 2: Config your mail.php by refering gmail config direction (http://support.google.com/mail/bin/answer.py?hl=en&answer=13287)

e.g., You can easily copy the following code into your project!!!
              'mail' => array(
  'class' => 'ext.mail.YiiMail',
  'transportType' => 'smtp',
      'transportOptions'=>array(
     'host'=>'smtp.gmail.com',
    'encryption'=>'ssl', // use ssl
     'username'=>'xxxx@gmail.com',
     'password'=>'xxxxxx',
     'port'=>465, // ssl port for gmail
       ),
  'viewPath' => 'application.views.mail',
  'logging' => true,
  'dryRun' => false
  ),

Step 3: Put the real logic in your view file or controller.

e.g.,

 $message = new YiiMailMessage;
 $message->setBody('Message content here with HTML', 'text/html');
 $message->subject = 'My Subject';
 $message->addTo('xxxx@xxxx');
 $message->from = "xxxxxx@gmail.com";//Yii::app()->params['adminEmail'];
 Yii::app()->mail->send($message);


帮自己宣传一下刚上线的网站 梦奇网;目前的提供的服务是 签证搜索 和 时间和日期。谢谢大家支持,SEO下!

5 comments:

  1. Thank you very much Great And Simple, It is very useful forme

    ReplyDelete
  2. I got this issue:
    Property "CWebApplication.mail" is not defined.

    ReplyDelete
    Replies
    1. Did you forget importing the extension?

      'import' => array( 'Ext.yii-mail.*',
      )

      Delete
    2. Oops...You are right! thanks

      Delete
  3. This comment has been removed by the author.

    ReplyDelete