我想在用户点击忘记密码时添加忘记密码表单。我已经有一个用PHP了。我正在使用MySQL数据库。
它应该转到忘记密码活动吗?
任何人都可以帮我或者提供示例代码吗?
答案 0 :(得分:0)
To send an email, you can use this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
P.S. taken from here
答案 1 :(得分:0)
查看此网站here
<?php
require_once 'DBOperations.php';
require 'PHPMailer/PHPMailerAutoload.php';
class Functions{
private $db;
private $mail;
public function __construct() {
$this -> db = new DBOperations();
$this -> mail = new PHPMailer;
}
public function resetPasswordRequest($email){
$db = $this -> db;
if ($db -> checkUserExist($email)) {
$result = $db -> passwordResetRequest($email);
if(!$result){
$response["result"] = "failure";
$response["message"] = "Reset Password Failure";
return json_encode($response);
} else {
$mail_result = $this -> sendEmail($result["email"],$result["temp_password"]);
if($mail_result){
$response["result"] = "success";
$response["message"] = "Check your mail for reset password code.";
return json_encode($response);
} else {
$response["result"] = "failure";
$response["message"] = "Reset Password Failure";
return json_encode($response);
}
}
} else {
$response["result"] = "failure";
$response["message"] = "Email does not exist";
return json_encode($response);
}
}
public function resetPassword($email,$code,$password){
$db = $this -> db;
if ($db -> checkUserExist($email)) {
$result = $db -> resetPassword($email,$code,$password);
if(!$result){
$response["result"] = "failure";
$response["message"] = "Reset Password Failure";
return json_encode($response);
} else {
$response["result"] = "success";
$response["message"] = "Password Changed Successfully";
return json_encode($response);
}
} else {
$response["result"] = "failure";
$response["message"] = "Email does not exist";
return json_encode($response);
}
}
public function sendEmail($email,$temp_password){
$mail = $this -> mail;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your.email@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = 'your.email@gmail.com';
$mail->FromName = 'Your Name';
$mail->addAddress($email, 'Your Name');
$mail->addReplyTo('your.email@gmail.com', 'Your Name');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Password Reset Request';
$mail->Body = 'Hi,<br><br> Your password reset code is <b>'.$temp_password.'</b> . This code expires in 120 seconds. Enter this code within 120 seconds to reset your password.<br><br>Thanks,<br>Learn2Crack.';
if(!$mail->send()) {
return $mail->ErrorInfo;
} else {
return true;
}
}
public function sendPHPMail($email,$temp_password){
$subject = 'Password Reset Request';
$message = 'Hi,nn Your password reset code is '.$temp_password.' . This code expires in 120 seconds. Enter this code within 120 seconds to reset your password.nnThanks,nLearn2Crack.';
$from = "your.email@example.com";
$headers = "From:" . $from;
return mail($email,$subject,$message,$headers);
}
}