您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ThinkPHP利用PHPMailer发送邮件

2024/4/11 20:06:33发布19次查看
phpmailer 是一个非常强大的 ph p发送邮件类,可以设定发送邮件地址、回复地址、邮件主题、html网页,上传附件,并且使用起来非常方便。
thinkphp3.2 phpmailer 发送邮件结合qq企业邮箱发送邮件
下载附件phpmailer解压到thinkphp\library\vendor
在common文件夹新建function.php
/** * 邮件发送函数 */ function sendmail($to, $title, $content) { vendor('phpmailer.phpmailerautoload'); $mail = new phpmailer(); //实例化 $mail->issmtp(); // 启用smtp $mail->host=c('mail_host'); //smtp服务器的名称(这里以qq邮箱为例) $mail->smtpauth = c('mail_smtpauth'); //启用smtp认证 $mail->username = c('mail_username'); //你的邮箱名 $mail->password = c('mail_password') ; //邮箱密码 $mail->from = c('mail_from'); //发件人地址(也就是你的邮箱地址) $mail->fromname = c('mail_fromname'); //发件人姓名 $mail->addaddress($to,"尊敬的客户"); $mail->wordwrap = 50; //设置每行字符长度 $mail->ishtml(c('mail_ishtml')); // 是否html格式邮件 $mail->charset=c('mail_charset'); //设置邮件编码 $mail->subject =$title; //邮件主题 $mail->body = $content; //邮件内容 $mail->altbody = "这是一个纯文本的身体在非营利的html电子邮件客户端"; //邮件正文不支持html的备用显示 return($mail->send()); }
添加配置文件
config.php
// 配置邮件发送服务器 'mail_host' =>'smtp.exmail.qq.com',//smtp服务器的名称 'mail_smtpauth' =>true, //启用smtp认证 'mail_username' =>'jufengjituan@gsjfjt.com',//你的邮箱名 'mail_from' =>'jufengjituan@gsjfjt.com',//发件人地址 'mail_fromname'=>'聚丰集团',//发件人姓名 'mail_password' =>'******',//邮箱密码 'mail_charset' =>'utf-8',//设置邮件编码 'mail_ishtml' =>true, // 是否html格式邮件
最后就是使用phpmailer发送邮件
<form action="__url__/add" method="post" enctype="multipart/form-data"> 邮箱:<input type="text" id="mail" name="mail"/> 标题:<input type="text" id="title" name="title"/> 内容<input type="text" id="content" name="content"/> <input class="button" type="submit" value="发送" style="margin: 0 auto;display: block;"/> </form>
public function add(){ if(sendmail($_post['mail'],$_post['title'],$_post['content'])) $this->success('发送成功!'); else $this->error('发送失败');}
phpmailer下载地址:https://github.com/phpmailer/phpmailer
推荐教程:thinkphp教程
以上就是thinkphp利用phpmailer发送邮件的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product