有助请顶,不好请评。
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. ng-repeat里创建的自定义指令

    在ng里,所有的指令在按照意愿正常工作之前的都需要编译一下,包含angularJS的自定义指令. ng模板里的所有指令都会在angularJS加载完毕之后编译一下,所以那些自定义指令和事件才能工作. ...

  2. iOS Architectures 浅谈

    iOS项目打包,或者只是在项目里面调用第三方静态库抑或是自己新建一个静态库,就要无可避免的和Architectures打交道.Architectures在Targets面板的Build Setting ...

  3. C语言 插入排序 算法导论chapter2

    #include <stdio.h> #define N 10 //INSERTION-SORT int main() { ,,,,,,,,,}; int key; ;j<N;j++ ...

  4. MVC安全防护

    一.XSS攻击 跨域脚本攻击(Cross Site Scripting),恶意植入前端代码,比如HTML代码和客户端脚本,异常js获取用户cookie然后跳转到别的站点. 防护措施 标签转换(如&qu ...

  5. bug 汇总

    联通营业厅充话费无法在线支付,chrome Python 64位安装包 win7 64 windows 10 右键菜单 Android studio IE11 layout

  6. iOS 内存管理

    一 . 内存管理 包括内存分配 和 内存清除 1.内存管理的范围 :人和继承于NSObject类的对象都需要进行内存管理,任何非对象类型的对象(基本数据类型 如 int char float doub ...

  7. Java后台发送邮件

    一.实现思路: 1.设置连接参数 2.设置邮件相关属性 3.发送邮件 二.相关需求: 1.导入jar包: 2.设置email.properties mail.smtp.host=smtp.163.co ...

  8. WPF 变量转换的实现

    有时候,我们传入的是一个值,但是真正显示的需要是另一个值,这时候就需要转换.比如我们传入一个枚举值,而不同的枚举值对于的图片是不一样的. 这时候就需要一个转换规则.WPF里面给我们提供了一个接口IVa ...

  9. php性能剖析的几款软件

    1. xhprof (http://pecl.php.net/package/xhprof)   facebook  2009年开源 2. xdebug 3. valgrind 4. cachegri ...

  10. PHP扩展安装mcrypt 提示没有可用包(No package php-mcrypt available)

    一.用CentOS的朋友基本在安装软件的时候默认都会想到用yum安装省事省时而且不会有错不需要担心依赖问题. php大部分的扩展都是可以再yum源里安装的,但是部分扩展是没有的,需要安装epel-re ...