欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

phpmailer綁定郵箱的實(shí)現(xiàn)方法

 更新時(shí)間:2016年12月01日 11:52:01   作者:牛逼的霍嘯林  
這篇文章主要介紹了phpmailer綁定郵箱的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了phpmailer綁定郵箱的配置、功能實(shí)現(xiàn)與相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了phpmailer綁定郵箱的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

效果如下:

1.配置

<?php
return array (
 'email_host' => 'smtp.aliyun.com',
 'email_port' => '25',
 'email_username' => 'diandodo@aliyun.com',
 'email_password' => 'xxxxxx',
 'email_from' => 'diandodo@aliyun.com',
 'email_fromname' => '點(diǎn)多多',
 'email_subject' => '助店寶商戶激活郵箱',
 'email_body' => "尊敬的用戶{$username}您好:
    您的激活碼為<font color='red'>{$code}</font>,請(qǐng)將激活碼輸入進(jìn)行驗(yàn)證! 激活碼有效期為6分鐘^_^",
);

2.發(fā)送函數(shù)

// 發(fā)送郵件
private function _sendEmail($email,$code,$username = '') {
    import('@.ORG.phpmailer');
    $mail = new PHPMailer(); //建立郵件發(fā)送類(lèi),類(lèi)名不一定與引入的文件名相同
    $mail->CharSet = "UTF-8";
    $mail->IsSMTP(); // 使用SMTP方式發(fā)送
    $mail->Host = C('email_host'); // 您的企業(yè)郵局域名
    $mail->SMTPAuth = true; // 啟用SMTP驗(yàn)證功能
    $mail->Username = C('email_username'); // 郵局用戶名(請(qǐng)?zhí)顚?xiě)完整的email地址)
    $mail->Password = C('email_password'); // 郵局密碼
    $mail->Port=C('email_port');
    $mail->From = C('email_from'); //郵件發(fā)送者email地址
    $mail->FromName = C('email_fromname');
    $mail->AddAddress("$email", "$username");
    $mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
    $mail->Subject = C('email_subject'); //郵件標(biāo)題
    $email_body = "尊敬的用戶<strong>{$username}</strong>您好:
    您的激活碼為<font color='red'>{$code}</font>,請(qǐng)將激活碼輸入進(jìn)行驗(yàn)證! 激活碼有效期為6分鐘^_^";
    $mail->Body = $email_body; //郵件內(nèi)容,上面設(shè)置HTML,則可以是HTML
    if(!$mail->Send())
    {
      return array('status'=>2,'info'=>$mail->ErrorInfo);
    } else {
      return array('status'=>1,'info'=>'發(fā)送成功');;
    }
}

3.生成驗(yàn)證碼保存到session中,并發(fā)送

// 發(fā)送郵箱激活碼
public function sendActivationcode() {
    session($this->activationtime, null);
    $activationtime = session($this->activationtime);
    $email = $this->_post('email', 'trim');
    if (IS_AJAX && (!$activationtime || time() > $activationtime)) {
      $activationcode = rand(1000, 9999);
      $res = $this->_sendEmail($email,$activationcode,$this->user['username']);
      if($res['status'] == 1) {
        //設(shè)置發(fā)送限制時(shí)間
        session($this->activationtime, time() + 50);
        session($this->activationcode, array('code' => $activationcode, 'time' => time() + 600));
        $this->ajaxReturn(array('result' => true));
      } else {
        //發(fā)送失敗寫(xiě)入日志文件
        $log = date('Y-m-d H:i:s') . " 發(fā)送失敗:{$res['info']}" . PHP_EOL;
        file_put_contents(RUNTIME_PATH . 'Log/activationcode.log', $log, FILE_APPEND);
        $this->ajaxReturn(array('result' => false, 'error' => $res['info']));
      }
    } else {
      $this->ajaxReturn(array('result' => false, 'error' => '錯(cuò)誤的請(qǐng)求'));
    }
}

4.驗(yàn)證并綁定

// 綁定郵箱
public function bind_email() {
    if (IS_POST) {
      // 獲取驗(yàn)證碼
      $activationcode = $this->_post('activationcode','trim');
      $email = $this->_post('email','trim');
      $session_activationcode = session($this->activationcode);
      if (time() > $session_activationcode['time'] || $activationcode != $session_activationcode['code']) {
        $this->error('驗(yàn)證碼有誤');
      } else {
        M('User')->where(array('id'=>$this->user['id']))->save(array('email'=>$email));
        $this->success('綁定成功',U('Account/my'));
      }
    } else {
      $this->display();
    }
}

小結(jié):

1. 這是一種思路,跟發(fā)送手機(jī)驗(yàn)證碼差不多。
2. 區(qū)別在于一個(gè)是發(fā)送短信,一個(gè)是發(fā)送郵件。
3. 二一個(gè),一個(gè)發(fā)送主體是阿里大魚(yú),一個(gè)發(fā)送主體是公司申請(qǐng)的郵箱。
4. 三一個(gè),發(fā)送短信收費(fèi),發(fā)送郵件免費(fèi)。

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論