'192.168.0.5', // 郵件伺服器 'auth' => true, // 需要驗證 'username' => 'foo', // SMTP 帳號 'password' => '123456'); // SMTP 密碼 $mailer = &Mail::factory('smtp',$params); // 建立 PEAR:: Mail 物件 // 使用 PEAR::Mail 寄信的表頭參數陣列 $headers = array( 'From' => encodeheader('旗標會員網站') . ' ', 'To' => $email, 'Subject' => encodeheader($subject), 'Content-Type' => "text/plain; charset=\"UTF-8\"", 'Content-Transfer-Encoding' => '8bit'); // 寄出郵件 $result = $mailer->send($email, $headers, $mailtext); if(PEAR::isError($result)) // 寄件失敗傳回 false return false; else // 寄件成功傳回 true return true; } // 建立新密碼的函式 // 當使用者忘記密碼時, 可利用密碼提示功能 // 由系統 (Reset.php) 產生一組密碼給使用者 function createpass() { // $chars 為含所有英文字母及數字的字串 $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $newpass = ''; // 以迴圈建立長度為 5 個字元的密碼 // 利用 (rand() % 35) 可得到 0~34 之間的任意數字 // 如此即可每次由 $chars 中隨機取出一個字元 for($i=0;$i<5;$i++) $newpass .= substr($chars, rand() % 35, 1); return $newpass; // 傳回隨機產生的字串 } ?>