Swift Mailer插件的使用
swift mailer插件的使用
作者:zccst
一、SwiftMailer是什么
官网:http://swiftmailer.org/docs/messages.html
批注:PHP中三大主流邮件发送插件
Zend Framework 框架中 包含的邮件类。(http://framework.zend.com/)
Swift Mailer (http://swiftmailer.org/)
PHPMailer (http://phpmailer.worxware.com)
三者对比,请参考文章:http://www.phpchina.com/phper/phper27/06-1.html
二、在Yii中如何配置
1,配置(../config/main.php)
// autoloading model and component classes'import'=>array(//...'ext.mail.Message',//...),'components'=>array( //... 'mail' => array( 'class' => 'ext.mail.Mail', 'transportType' => 'smtp', 'transportOptions' => array( 'host' => 'email.corporation.com', 'port' => 8082, 'username' => '', 'password' => '', //'encryption' => 'starttls' ), 'viewPath' => 'application.views.mail', 'debug' => false ), //...),
$message = new Message();// subject$message->subject = "XX公司XX通知";// from$message->from = 'service@companyName.com';// to$message->to = array('a@a.com','b@b.com');// cc and bcc// content$message->setBody($body);// attachment$attachments = Attachment::model()->findAll("ref_id = $repair_info_Id");if(count($attachments) > 0){foreach ($attachments as $o){$attach = Swift_Attachment::newInstance(base64_decode($o->data),$o->file_path);$message->attach($attach);}}Yii::app()->mail->send($message);