PS. 如果只是企業內部管理人員的申請則不需要郵件確認!
$result = $stmt->execute(); if($result){ //假如新增會員成功, 進行發送確認信....... $sendMailResult = sendMail($mem_mail,$mem_name,$mem_chkcode); if($sendMailResult){ //假如發送確認信成功....... header('Location:./?page=mem_addmem_ok&msg=3'); }else{ //否則表示發送確認信失敗...... header('Location:./?page=mem_addmem_ok&msg=2'); } }else{ //這裡表示新增會員失敗........ header('Location:./?page=mem_addmem_ok&msg=1'); }
<?php function sendMail($mailto,$name,$chkcode){ $subject = "=?UTF-8?B?".base64_encode('TS緹絲坊網站會員功能啟用通知')."?="; $content = $name.'您好, 感謝申請會員<br>' .'TS緹絲坊網站會員功能啟用通知<br>' .'請點選<a href="localhost/TS_PHP_20200523/?page=mem_login&mailok=1&mem_mail=' .$mailto.'&mem_chkcode='.$chkcode.'">此連結回覆確認信箱</a><br>' .'此信件為系統自動發送, 請勿點選回覆信件'; $header = "From: server@gmail.com\r\n"; $header .= "Content-type: text/html; charset=utf8"; //mail(收件者,信件主旨,信件內容,信件檔頭資訊) $result = mail($mailto, $subject, $content, $header); return $result; } ?>
<?php //收到 msg = 1 > 新增資料失敗....... //收到 msg = 2 > 新增資料成功, 但是發信失敗, ....... //收到 msg = 3 > 新增資料成功, 發信也成功, 請會員去收信, ..... if(isset($_GET['msg']) && $_GET['msg']==3){ $msg = '<h2>感謝您註冊新會員成功!<br>' .'請前往郵件信箱收信!<br>' .'點選驗證連結再回到網站!</h2>'; } if(isset($_GET['msg']) && $_GET['msg']==2){ $msg = '<h2>目前系統可能因忙碌而產生發送確認信件失敗,<br> 請過些時候前往 [客服中心]=>[已申請會員,重發確認信]</h2>'; } if(isset($_GET['msg']) && $_GET['msg']==1){ $msg = '<h2>目前系統可能因忙碌而產生會員申請失敗,<br>請過些時候再重新申請會員</h2>'; } echo $msg; ?>
<?php require_once('../shared/conn_pdo.php'); //判斷是否來自確認信並連結回來的=>更新會員身份等級為2============ if( isset($_GET['mailok']) && $_GET['mailok']==1 ){ try{ $sql_str = "UPDATE member SET mem_level=2 WHERE mem_mail=:mem_mail AND mem_chkcode=:mem_chkcode"; $stmt = $conn->prepare($sql_str); $mem_mail = $_GET['mem_mail']; $mem_chkcode = $_GET['mem_chkcode']; $stmt->bindParam(':mem_mail' ,$mem_mail); $stmt->bindParam(':mem_chkcode' ,$mem_chkcode); $stmt->execute(); } catch (PDOException $e ){ die("Error!: ". $e->getMessage()); } } ?>