php – YII – 使用sendGrid邮寄
发布时间:2020-12-13 16:48:08 所属栏目:PHP教程 来源:网络整理
导读:我想在yii php框架中用SendGrid发送邮件. 这是我发送邮件的动作代码: public function actionSendmail(){ Yii::setPathOfAlias('Libs',Yii::app()-basePath.'/lib'); Yii::setPathOfAlias('SendGrid',Yii::app()-basePath.'/lib/sendgrid-php/SendGrid'); Y
我想在yii php框架中用SendGrid发送邮件.
这是我发送邮件的动作代码: public function actionSendmail() { Yii::setPathOfAlias('Libs',Yii::app()->basePath.'/lib'); Yii::setPathOfAlias('SendGrid',Yii::app()->basePath.'/lib/sendgrid-php/SendGrid'); Yii::import('SendGrid.*'); Yii::import('Libs.sendgrid-php.SendGrid',true); $sendgrid = new SendGrid('uname','pwd'); $mail = new SendGridMail(); $mail->addTo('to-email')-> setFrom('from-email')-> setSubject('Subject goes here')-> setText('Hello World!')-> setHtml('<strong>Hello World!</strong>'); $sendgrid->smtp->send($mail); $this->render('mail'); } 显示错误:
06 { 07 //the available ports 08 const TLS = 587; 09 const TLS_ALTERNATIVE = 25; 10 const SSL = 465; 11 12 //the list of port instances,to be recycled 13 private $swift_instances = array(); 14 protected $port; 15 16 public function __construct($username,$password) 17 { 18 require_once ROOT_DIR . 'lib/swift/swift_required.php'; 19 call_user_func_array("parent::__construct",func_get_args()); 20 21 //set the default port 22 $this->port = Smtp::TLS; 23 } 24 25 /* setPort 26 * set the SMTP outgoing port number 27 * @param Int $port - the port number to use 28 * @return the SMTP object 29 */ 30 public function setPort($port) 如何解决这个问题? 解决方法
得到它了:
public function actionSendmail() { define('ROOT_DIR',Yii::app()->basePath . '/lib/sendgrid-php/'); define('SWIFT_REQUIRED_LOADED',true); Yii::import('application.lib.sendgrid-php.SendGrid'); Yii::import('application.lib.sendgrid-php.lib.swift.classes.Swift',true); Yii::registerAutoloader(array('Swift','autoload')); Yii::import('application.lib.sendgrid-php.lib.swift.swift_init',true); Yii::setPathOfAlias('SendGrid',Yii::app()->basePath . '/lib/sendgrid-php/SendGrid/'); $sendgrid = new SendGrid('uname','pwd'); $mail = new SendGridMail(); $mail->addTo('to-email')-> setFrom('from-email')-> setSubject('Subject goes here')-> setText('Hello World!')-> setHtml('<strong>Hello World!</strong>'); $sendgrid->smtp->send($mail); $this->render('mail'); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- WordPress中Gravatar头像缓存到本地及相关优化的技巧
- php – MySQL JSON编码字符串在INSERT..SELECT后损坏
- php – WordPress用户身份验证过程
- php – 警告:preg_match()[function.preg-match]:未知的修
- PHP 中常量的知识整理
- php – Propel ORM – 加入不相关的表
- php – 使用singleton检索对象而不是new运算符时netbeans自
- php – if(!Variable)和if(isset($variable))之间有什么区
- php – MYSQL查询 – 获取与该帖子相关的最新评论
- PHP使用file_get_content设置头信息的方法