CI框架使用PHPmail插件发送QQ邮件:

简介:   购买阿里云相关服务,这里可以领取优惠券, 有的产品5折优惠哟, 注意, 领取的优惠券30天内有效,尽快使用:领取方式:进入链接后 页面下拉 一键领取全部 或者按需每次领取对应的优惠,领取链接:点击此处链接领取https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=s306eooi&utm_source=s306eooi如果有需要, 可以帮助部署LNMP环境, 价格80,学生可以商量 有助请顶,不好请评。

 

 

购买阿里云相关服务,这里可以领取优惠券, 有的产品5折优惠哟, 注意, 领取的优惠券30天内有效,尽快使用:
领取方式:进入链接后 页面下拉 一键领取全部 或者按需每次领取对应的优惠,领取链接:
点击此处链接领取
https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=s306eooi&utm_source=s306eooi
如果有需要, 可以帮助部署LNMP环境, 价格80,学生可以商量

最新阿里云优惠

有助请顶,不好请评。
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

相关文章
|
1月前
|
安全 PHP Apache
thinkphp3.2发送邮件并发送附件
thinkphp3.2发送邮件并发送附件
31 0
thinkphp3.2发送邮件并发送附件
|
30天前
|
Java
使用java底层实现邮件的发送(含测试,源码)
使用java底层实现邮件的发送(含测试,源码)
9 0
|
3月前
|
前端开发
使用 PHPMailer 实现邮件的实时发送
使用 PHPMailer 实现邮件的实时发送
24 0
使用 PHPMailer 实现邮件的实时发送
|
3月前
|
移动开发 Python HTML5
Python办公自动化【发送普通邮件、发送HTML邮件、发送附件邮件-smtplib、批量发送邮件-smtplib、发送邮件-zmail】(八)-全面详解(学习总结---从入门到深化)
Python办公自动化【发送普通邮件、发送HTML邮件、发送附件邮件-smtplib、批量发送邮件-smtplib、发送邮件-zmail】(八)-全面详解(学习总结---从入门到深化)
43 0
|
10月前
关于QQ如何向他人发送文件夹的解决方案
关于QQ如何向他人发送文件夹的解决方案
83 0
小储云邮件通知插件配置教程
设置通知配置,配置完成之后,有订单-工单-提现可以通知站长,提升了平台处理效率!
371 0
小储云邮件通知插件配置教程
|
Java Spring 容器
SpringBoot整合JavaMail 可以发送单纯的文字邮件 也可发送有html文件或者发送压缩包多文件邮件
SpringBoot整合JavaMail 可以发送单纯的文字邮件 也可发送有html文件或者发送压缩包多文件邮件
196 0
SpringBoot整合JavaMail 可以发送单纯的文字邮件 也可发送有html文件或者发送压缩包多文件邮件
|
Linux iOS开发 MacOS
命令行搞一切之发送有附件的邮件
今天我们看到了一种从 Linux 命令行发送电子邮件和附件的方法。还有一些其他程序,如“ mutt ”和“ Sendmail ”,它们与“ mail ”类似,可以用于相同的目的。
435 0
|
安全 Java 网络安全
使用IDEA实现第三方发送QQ邮件时SSL protocol问题的解决
3、使用IDEA实现第三方发送QQ邮件时SSL protocol问题的解决 **问题描述:**使用IDEA实现第三方发送QQ邮件,使用SSL安全协议时出现SSLHandshakeException如下图 **解决方案:**百度后发现问题原因是本地jdk1.8配置中将SSLv3协议禁用了,将相关配置修
|
数据安全/隐私保护 Android开发
如何使用QQ发送加密邮件
电子邮件是工作和生活的必须。但是,电子邮件是“明信片”(明文收发),无法保证邮件机密信息在邮件流转过程和在邮件服务器中存储的安全。怎么办?
如何使用QQ发送加密邮件