• thinkphp引入phpmailer发送邮件


    在tp系统文件下的Extend->Vendor->Zend下放置phpmailer文件包,并把phpmailer类改名。

    看目录:

    然后参考tp手册:

    so...我的导入方法代码为:

    Vendor('Zend.PHPMailer.classphpmailer');

    完整的邮件发送代码:

    首先是发送方法:

    public function sendmail($sendto_email, $user_name, $subject, $bodyurl)
        {
            Vendor('Zend.PHPMailer.classphpmailer');
            $mail = new PHPMailer();
            $mail->IsSMTP();                  // send via SMTP    
             
            $mail->Host = "你的邮件服务域名";   // SMTP servers    
            $mail->SMTPAuth = true;           // turn on SMTP authentication    
            $mail->Username = "XXXX";     // SMTP username  注意:普通邮件认证不需要加 @域名    
            $mail->Password = "******"; // SMTP password    
            $mail->From = "axx@xxx.com";      // 发件人邮箱    
            $mail->FromName = "管理员";  // 发件人    
    
            $mail->CharSet = "utf-8";   // 这里指定字符集!    
            $mail->Encoding = "base64";
            $mail->AddAddress($sendto_email, $user_name);  // 收件人邮箱和姓名    
            $mail->SetFrom('axx@xxx.com', 'XXXXXXX有限公司');
    
            $mail->AddReplyTo("axx@xxx.com", 'xxxxxxxx有限公司');
            //$mail->WordWrap = 50; // set word wrap 换行字数    
            //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件    
            //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    
            $mail->IsHTML(true);  // send as HTML    
            // 邮件主题    
            $mail->Subject = $subject;
            // 邮件内容    
            $mail->Body = '<html><head>   
    <meta http-equiv="Content-Language" content="zh-cn"/>   
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>   
    </head>   
    <body> 
    <div style="60%;padding:30px 20px;background:#F9F9F9;">
    <span style="font-weight:bold;font-size:16px;">Hi,' . $user_name . '</span><br/>
    欢迎您注册<b>XXX公司网站</b><br/>
    请点击下面的连接完成注册(有效期一小时):<br/>
    ' . $bodyurl . '<br/>
    <font style="color:#999;">如果以上链接无法点击,请将上面的地址复制到你的浏览器(如IE)的地址栏完成激活</font><br/>
    http://www.XXX.com
    </div>
    </body> 
    
    </html>   
    ';
            $mail->AltBody = "text/html";
            
            if (!$mail->Send())
            {
                  $mail->ClearAddresses();
                echo "邮件错误信息: " . $mail->ErrorInfo;
                exit;
            }
            else
            {
                 $mail->ClearAddresses();
               // $this->assign('waitSecond', 6);
    //            $this->success("注册成功,系统已经向您的邮箱:{$sendto_email}发送了一封激活邮件!请您尽快激活~~<br />");
                $this->redirect('sendhtml', array('send' => 5,'email'=>$sendto_email));
            }
        }

    其次调用发送方法:

    $this->sendmail($_POST['email'], $_POST['nickname'], $subject, $bodyurl);
  • 相关阅读:
    泛型类,泛型方法的使用
    Mapper注解与MapperScan注解
    Configuration注解
    LA 4254 Processor (二分 + 贪心)
    UVa 10382 Watering Grass (贪心 区间覆盖)
    UVA 10795 A Different Task (递归)
    LA 3401 Colored Cubes (搜索 + 暴力)
    uva11464 Even Parity (枚举+递推)
    icpc2021 昆明 K (dfs爆搜)
    hdu3533 (bfs + 模拟)
  • 原文地址:https://www.cnblogs.com/wenzichiqingwa/p/2956168.html
Copyright © 2020-2023  润新知