thinkphp中怎么使用phpmailer发送邮件
phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎么集成phpmailer到thinkphp框架了,有需要了解的朋友可参考。
phpmailer发送邮件功能很强大,今天真正的体验一下,简单说一下配置,本人是在thinkphp中是用的.
配置步骤:
1.后台配置发送邮件类,位置admin/common/common.php中,代码如下:
- function sendmail($tomail,$title,$content)
- {
- /*邮件设置信息*/
- $email_set = C(‘EMAIL_SET‘);
- Vendor(‘phpmailer.class#phpmailer‘);
- Vendor("phpmailer.class#smtp"); //可选,否则会在class.phpmailer.php中包含
- $mail = new PHPMailer(true); //实例化PHPMailer类,true表示出现错误时抛出异常
- $mail->IsSMTP(); // 使用SMTP
- $mail->CharSet ="UTF-8";//设定邮件编码
- $mail->Host = $email_set[‘Host‘]; // SMTP server
- $mail->SMTPDebug = 1; // 启用SMTP调试 1 = errors 2 = messages
- $mail->SMTPAuth = true; // 服务器需要验证
- $mail->Port = $email_set[‘port‘]; // 设置端口
- // $mail->SMTPSecure = "ssl";
- /*
- $mail->SMTPSecure = "ssl";
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 465;
- */
- $mail->Username = $email_set[‘email_user‘]; //SMTP服务器的用户帐号
- $mail->Password = $email_set[‘email_pwd‘]; //SMTP服务器的用户密码
- $mail->AddReplyTo($email_set[‘email‘],$email_set[‘email_name‘]); //收件人回复时回复到此邮箱,可以多次执行该方法
- if (is_array($tomail)){
- foreach ($tomail as $m){
- $mail->AddAddress($m, ‘user‘);
- }
- }else{
- $mail->AddAddress($tomail, ‘user‘);
- }
- $mail->SetFrom($email_set[‘email‘],$email_set[‘email_name‘]);
- // $mail->AddAttachment(‘./img/phpmailer.gif‘); // 添加附件,如果有多个附件则重复执行该方法
- $mail->Subject = $title;
- //以下是邮件内容相关
- $mail->Body = $content;
- $mail->IsHTML(true);
- //$body = file_get_contents(‘tpl.html‘); //获取html网页内容
- // $mail->MsgHTML(eregi_replace("[]",‘‘,$body));
- return $mail->Send()? true:false;
- }
2:配置文件中配置参数,代码如下:
- /*邮件设置*/
- ‘EMAIL_SET‘=>array(
- ‘Host‘=> "smtp.163.com",
- ‘Port‘=>‘25‘,
- ‘email_user‘=>‘liuying‘,
- ‘email_pwd‘=>‘123456‘,
- ‘email‘=>‘‘,
- ‘email_name‘=>‘86市场网‘,
- )
3.测试发送代码,代码如下:
sendmail(’‘,‘您好’,‘我是内容’);
相关推荐
Skyline 2020-05-14
poplpsure 2020-04-07
hedongli 2019-12-31
缘起宇轩阁 2019-11-08
xuebingnan 2019-09-03
一个过客 2017-08-18
whucaodi 2012-09-24
会写code的凳子哥 2016-01-16
olyqcool 2015-09-02
ahxxx 2019-06-27
xishizhaohua 2019-06-26
lbcmail 2019-06-26
微麦PHP 2019-06-26
superhosts 2019-06-26
ahxxx 2019-06-25
怕什么真理无穷 2019-06-25
superhosts 2019-06-20