有助请顶,不好请评。
0:33 2016/3/12
CI框架使用PHPmail插件发送QQ邮件:
发送成功,不过修改了主机参数,还包含了一个phpmail中的一个另外的文件,详见下方:
参见:http://codeigniter.org.cn/forums/thread-11484-1-1.html
博文摘写:

不知道大家在使用CI的email类的时候,是否有遇到麻烦,特别是使用smtp方式的时候,我遇到的是只能使用126邮箱,QQ和gmail都发送不成功,很无懒,最后在我们另外一个站上直接使用了phpmailer,但是直接使用phpmailer的话,有时候不是很方便,特别你的很多功能都是基于CI完成的时候,要相互依赖就不方便了,所以在想,那是否可以将phpmailer集成到CI中呢,像使用email类这样使用他,功夫不负有心人,在网上居然有人分享了很多内容,但是之前的CI是支持插件功能的,所以很多文章都是说的基于插件的方式,现在CI有了新的调整,基于类的方式。最后找到一篇文章,可以帮助我们解决这个问题,将phpmailer集成到CI中,成为类,大家可以去到这个url查看详细的介绍:http://blog.qoding.us/2011/09/codeigniter-using-phpmailer-to-send-email-via-gmail/

我将他的部分内容拷贝如下:

最近要處理一個電子報系統,再用 CI 那跛腳 Email Class 大概會被客訴到瘋掉。所以還是認命改用老牌的 PHPMailer Library。稍微試一下,發現在 CI 裡使用 PHPMailer 相當無痛,先到官網下載一份 PHPMailer (本文完成時的最新版本是 5.2.0),解壓縮後把整個資料夾丟到 CI\application\libraries\PHPMailer_5.2.0。接著在 libraries 下建立新檔案,就叫 mailer.php 好了。

PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mailer {

var $mail;

public function __construct()
{
require_once('PHPMailer_5.2.0/class.phpmailer.php');

// the true param means it will throw exceptions on errors, which we need to catch
$this->mail = new PHPMailer(true);

$this->mail->IsSMTP(); // telling the class to use SMTP

$this->mail->CharSet = "utf-8"; // 一定要設定 CharSet 才能正確處理中文
$this->mail->SMTPDebug = 0; // enables SMTP debug information
$this->mail->SMTPAuth = true; // enable SMTP authentication
$this->mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$this->mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$this->mail->Port = 465; // set the SMTP port for the GMAIL server
$this->mail->Username = "YOUR_GAMIL@gmail.com";// GMAIL username
$this->mail->Password = "YOUR_PASSWORD"; // GMAIL password
$this->mail->AddReplyTo('YOUR_GAMIL@gmail.com', 'YOUR_NAME');
$this->mail->SetFrom('YOUR_GAMIL@gmail.com', 'YOUR_NAME');
}

public function sendmail($to, $to_name, $subject, $body){
try{
$this->mail->AddAddress($to, $to_name);

$this->mail->Subject = $subject;
$this->mail->Body = $body;

$this->mail->Send();
echo "Message Sent OK</p>\n";

} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
}

/* End of file mailer.php */

复制代码

接著在 Controller 裡呼叫這支 library 就可以了,範例如下。
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Epaper extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function send(){
$mail_body = "落落長的內文";
$this->load->library('mailer');
$this->mailer->sendmail(
'address@example.com',
'收件人',
'這是測試信 '.date('Y-m-d H:i:s'),
$mail_body
);
}
}
/* End of file epaper.php */
复制代码

至於多重收件人之類的設定就要另外再變化了,這邊只是最入門的版本。

注意:我用的时候需要额外包含一个文件,另外,我用的QQ邮箱,所以需要修改主机参数:
require_once('PHPMailer/class.smtp.php');

// $this->mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$this->mail->Host = "smtp.qq.com"; // sets GMAIL as the SMTP server

修改后的一个函数:
public function __construct()
{
// require_once('PHPMailer_5.2.0/class.phpmailer.php');
// require_once('../../../PHPMailer/class.phpmailer.php');
require_once('PHPMailer/class.phpmailer.php');
require_once('PHPMailer/class.smtp.php');

// the true param means it will throw exceptions on errors, which we need to catch
$this->mail = new PHPMailer(true);

$this->mail->IsSMTP(); // telling the class to use SMTP

$this->mail->CharSet = "utf-8"; // 一定要設定 CharSet 才能正確處理中文
$this->mail->SMTPDebug = 0; // enables SMTP debug information
$this->mail->SMTPAuth = true; // enable SMTP authentication
$this->mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $this->mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$this->mail->Host = "smtp.qq.com"; // sets GMAIL as the SMTP server
$this->mail->Port = 465; // set the SMTP port for the GMAIL server
// $this->mail->Username = "YOUR_GAMIL@gmail.com";// GMAIL username
// $this->mail->Password = "YOUR_PASSWORD"; // GMAIL password
// $this->mail->AddReplyTo('YOUR_GAMIL@gmail.com', 'YOUR_NAME');
// $this->mail->SetFrom('YOUR_GAMIL@gmail.com', 'YOUR_NAME');
$this->mail->Username = "********@qq.com";// GMAIL username
$this->mail->Password = "qnrxylzlojcobcej"; // GMAIL password
$this->mail->AddReplyTo('******@qq.com', '测试的邮件回复人名称');
$this->mail->SetFrom('*******@qq.com', '测试的发件人名称');
}

参见上面这个博客成功发送。

另一个博客:在codeigniter的helper用phpmailer 发送邮件 参见:http://blog.csdn.net/jiaochangyun/article/details/7711656

CI框架使用PHPmail插件发送QQ邮件:的更多相关文章

  1. 5分钟 wamp下php phpmaile发送qq邮件 2015最新方法说明

    13:40 2015/11/20 5分钟 wamp下php phpmaile发送qq邮件 2015最新方法说明 关键点:现在qq邮箱开通smtp服务后会给你一个很长的独立新密码,发邮件配置中的密码需要 ...

  2. 【python】脚本连续发送QQ邮件

    今天习得用python写一个连续发送QQ邮件的脚本,经过测试,成功给国内外的服务器发送邮件,包括QQ邮箱.163邮箱.google邮箱,香港科技大学的邮箱和爱丁堡大学的邮箱.一下逐步解答相关技巧. 首 ...

  3. Java发送QQ邮件

    面试的时候被问到这个问题,别人问我用Java发过邮件没有,被问得一脸懵逼.然后就研究了一下,不是很难,按照网上的方法折腾了几天就搞出来了. 首先,使用QQ邮箱发送邮件之前需要在邮箱里面配置,开启pop ...

  4. python3:利用SMTP协议发送QQ邮件+附件

    转载请表明出处:https://www.cnblogs.com/shapeL/p/9115887.html 1.发送QQ邮件,首先必须知道QQ邮箱的SMTP服务器 http://service.mai ...

  5. java mail Received fatal alert: handshake_failure java 无法发送邮件问题 java 发送qq邮件(含源码)

     java 无法发送邮件问题 java 发送qq邮件 报错:java mail Received fatal alert: handshake_failure (使用ssl) javax.mail.M ...

  6. Quartz.NET浅谈一 : 简单Job使用(定时发送QQ邮件)

    Quartz.NET是一个全功能的开源作业调度系统,可用于从最小的应用程序到大型企业系统. 直接上代码吧... 一.新建一个控制台项目 略过 二.安装Nuget包 三.创建发送邮箱辅助工具类 stat ...

  7. 电子邮件协议及GO发送QQ邮件

    目录 一.电子邮件的工作机制 1.1 SMTP 1.2 POP3 1.3 IMAP 二.邮件地址 三.MIME信息 四.使用golang发送qq邮件 一.电子邮件的工作机制 提供电子邮件服务的协议叫做 ...

  8. java代码如何发送QQ邮件

    近来想写一个qq之间互相发送邮件的工具.奈何一直报错服务错误: org.apache.commons.mail.EmailException: Sending the email to the fol ...

  9. 使用python发送QQ邮件

    这里用到了Python的两个包来发送邮件: smtplib 和 email . Python 的 email 模块里包含了许多实用的邮件格式设置函数,可以用来创建邮件“包裹”.使用的 MIMEText ...

随机推荐

  1. Windows7安装 .net framework 4.0

    1.首先下载安装包.net framework 4.0点击下载即可 2.安装,双击下载好的安装包

  2. PPM图片格式及其C读写代码

    PPM图像格式介绍 PPM图像格式是由Jef Poskanzer 大叔,在我出生那一年,也就是1991年所创造的,碰巧的是PPM也是天蝎座. PPM(Portable Pixmap Format)还有 ...

  3. Django模板与Vue.js冲突问题

    参考: https://my.oschina.net/soarwilldo/blog/755984 方法1:修改vue.js的默认的绑定符号 Vue.config.delimiters = [&quo ...

  4. 用任务计划管理计划任务对付任务计划-禁止WPS提示升级

    作为一名至今还在坚守着64位XP的XP用到死星人,因为准备升级电脑,所以准备移民外星,开始使用Windows7.其实我新电脑买来一年了,为了坚守XP,扔在一边没有装(华硕Z9PE-D8 WS主板,双E ...

  5. Android带图片的Toast(自定义Toast)

    使用Android默认的Toast Toast简介: Toast是一个简单的消息显示框,能够短暂的出现在屏幕的某个位置,显示提示消息. 默认的位置是屏幕的下方正中,一般Toast的使用如下: Toas ...

  6. JQuery实现无刷新下拉加载图片

          最近做的一个项目需要做页面无刷新下拉加载图片,调研了一番,大多都采用检测滚动条达到底部,然后利用ajax加载下一页数据对页面数据进行添加,根据这一逻辑,自己写了一个,具体代码如下: JQu ...

  7. Python之路,Day8 - Python基础 面向对象高级进阶与socket基础

    类的成员 类的成员可以分为三大类:字段.方法和属性 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存中就有多少个普通字段.而其他的成员,则都是保存在类中,即:无论对象的 ...

  8. toArray(),toJson(),hidden([ ]),visible([ ])

    toArray() 转换为数组,hidden()不输出的字段 public function index(){ $user = model('User'); $data = $user::)-> ...

  9. iOS10 远程推送代码 以及服务器端代码(.net)

    // // AppDelegate.m // MyPushDemo // // Created by justapple on 16/12/25. // Copyright © 2016年 dengq ...

  10. js中== 和===中的区别

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...