1.Thinkphp 发送邮件内容来自:http://www.thinkphp.cn/code/32.html

/**
* 系统邮件发送函数
* @param string $to 接收邮件者邮箱
* @param string $name 接收邮件者名称
* @param string $subject 邮件主题
* @param string $body 邮件内容
* @param string $attachment 附件列表
* @return boolean
*/
function think_send_mail($to, $name, $subject = '', $body = '', $attachment = null){
$config = C('THINK_EMAIL');
vendor('PHPMailer.class#phpmailer'); //从PHPMailer目录导class.phpmailer.php类文件
$mail = new PHPMailer(); //PHPMailer对象
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->SMTPSecure = 'ssl'; // 使用安全协议
$mail->Host = $config['SMTP_HOST']; // SMTP 服务器
$mail->Port = $config['SMTP_PORT']; // SMTP服务器的端口号
$mail->Username = $config['SMTP_USER']; // SMTP服务器用户名
$mail->Password = $config['SMTP_PASS']; // SMTP服务器密码
$mail->SetFrom($config['FROM_EMAIL'], $config['FROM_NAME']);
$replyEmail = $config['REPLY_EMAIL']?$config['REPLY_EMAIL']:$config['FROM_EMAIL'];
$replyName = $config['REPLY_NAME']?$config['REPLY_NAME']:$config['FROM_NAME'];
$mail->AddReplyTo($replyEmail, $replyName);
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($to, $name);
if(is_array($attachment)){ // 添加附件
foreach ($attachment as $file){
is_file($file) && $mail->AddAttachment($file);
}
}
return $mail->Send() ? true : $mail->ErrorInfo;
}

此函数只能在ThinkPHP中使用且需要phpmailer扩展的支持;
phpmailer扩展的放置目录为 ThinkPHP/Extend/Vendor/PHPMailer/class.phpmailer.php
phpmail的下载地址:
http://sourceforge.net/projects/phpmailer/files/

然后下载 Download PHPMailer_v5.1.zip (111.7 kB)
使用此函数 必须在项目中加入以下配置项

//邮件配置
'THINK_EMAIL' => array(
'SMTP_HOST' => 'smtp.aaa.com', //SMTP服务器
'SMTP_PORT' => '465', //SMTP服务器端口
'SMTP_USER' => 'mail@aaa.com', //SMTP服务器用户名
'SMTP_PASS' => 'password', //SMTP服务器密码
'FROM_EMAIL' => 'mail@aaa.com', //发件人EMAIL
'FROM_NAME' => 'ThinkPHP', //发件人名称
'REPLY_EMAIL' => '', //回复EMAIL(留空则为发件人EMAIL)
'REPLY_NAME' => '', //回复名称(留空则为发件人名称)
),

2.发送邮件更简单版,具体来自内容请参考 ThinkPHP 中使用 PHPMailer 发送邮件(支持163、QQ邮箱,附下载)

3.解决smtp server connect failed(连接smtp服务器失败)

Using WampServer 2.2 I just edit php.ini in C:\wamp\bin\php\php5.3.13 then uncommentextension=php_openssl.dll

(使用的是wamp集成环境,所以要到具体的目录下面看php.ini中

;extension=php_openssl.dll

前面的分号是否去除了),xampp的也是修改php.ini文件

解决smtp服务器连接不上

  • 添加 C:\PHP\ext 到系统变量中,具体根据你php安装路径为准
  • 将 php 根目录下的 libeay32.dll,ssleay32.dll 两个文件 复制到 C:\WINDOWS\system32 中
  • 重启服务器

参考了:Socket transport “ssl” in PHP not enabled

Thinkphp 使用gmail发送邮件的更多相关文章

  1. 使用Gmail发送邮件心得

    /// <summary> /// 发送邮件 /// </summary> /// <returns></returns> public static ...

  2. thinkphp 3.2 发送邮件(Phpmailer)

    1.在该模板下Conmon模块函数公共目录新建一个function.php <?php function Sendemail(){ vendor('PHPMailer.class#phpmail ...

  3. thinkphp使用PHPMailer发送邮件

    第一步:准备PHPMailer 使用PHPMailer发送邮件,首先下载个PHPMailer 将下载的PHPMailer放到ThinkPHP文件夹里面的ThinkPHPExtendVendor 第二步 ...

  4. 使用php+gmail 发送邮件

    <?php namespace app\index\controller; use think\Controller; use PHPMailer\PHPMailer; class Test e ...

  5. SpringBoot 2.x 集成QQ邮箱、网易系邮箱、Gmail邮箱发送邮件

    在Spring中提供了非常好用的 JavaMailSender接口实现邮件发送,在SpringBoot的Starter模块中也为此提供了自动化配置. 项目源码已托管在Gitee-SpringBoot_ ...

  6. 《PHP发送邮件PHPMailer》系列分享专栏

    <PHP发送邮件PHPMailer>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201726.html 文章 PHPMailer ...

  7. 利用PHPMailer发送邮件时报错

    利用thinkphp集成PHPMailer发送邮件时报错:Failed to connect to server: Unable to find the socket transport “ssl” ...

  8. phpmailer 发送邮件(一)

    phpmailer下载地址: PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问) php 设 ...

  9. PHPMailer发送邮件(一)

    Github 地址:(已更新,适用于旧版) PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问 ...

随机推荐

  1. 计算N的阶层

    int factorial(int n) { int i, result; ; i <= n; i++) result *= i; return result; } int factorial2 ...

  2. tar常用解包

    (1)常见解压缩包 .tar解包 tar -xvf  xxxx.tar 打包 tar -cvf xxxx .tar.bz2解包 bzip2 -d  xxxx.tar.bz2        #会解压成. ...

  3. 命令cp

    cp 源 目标cp -r  递归复制整个目录cp -v  显示复制的详细信息

  4. 清空具有外键约束的表时报ERROR 1701(42000)的解决办法

    ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (`furion`.`tbl_fr ...

  5. RxJava 复杂场景 Schedulers调度

    参考: https://blog.piasy.com/2016/10/14/Complex-RxJava-2-scheduler/ 以Zip为例,学习Schedulers的线程调度 要求: * cre ...

  6. HW6.1

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. A Tour of Go Range continued

    You can skip the index or value by assigning to _. If you only want the index, drop the ", valu ...

  8. [六]SpringMvc学习-文件上传

    1.单文件上传 1.1修改配置文件 <bean id="multipartResolver" class="org.springframework.web.mult ...

  9. sql2008_x64 读取excel

    sql2008_x64 读取excel 下载64bit 版的AccessDatabaseEngine_x64:http://www.microsoft.com/en-us/download/detai ...

  10. java中调用dll文件的两种方法

    一中是用JNA方法,另外是用JNative方法,两种都是转载来的, JNA地址:http://blog.csdn.net/shendl/article/details/3589676   JNativ ...