Android Question Password forgotten & php on remote server

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
The php file on my remote server allows to send a new password by email (php file below). The password is contained in the $mdp variable and the email address in the $mail variable.
With B4A I would like to transfer the password and the email addresses in the respective variables of the php file and send email.
I imagine you should use OkHttpUtilis2, but no idea for code.
Can someone give me an idea or track to code properly
Thank you

B4X:
<?php
$mail1 ="[email protected]";
$mdp = "abcd1234A";

$message2 = "Votre nouveau mot de passe";
$message_out = "Votre nouveau mot de passe est : "."$mdp". " .";

   $to    = "$mail1,[email protected]";

   // adresse MAIL OVH liée à l’hébergement.
   $from  = "[email protected]";

   ini_set("SMTP", "smtp.pau.jazz.fr");   // Pour les hébergements mutualisés Windows de OVH
 
   // *** Laisser tel quel

   $JOUR  = date("Y-m-d");
   $HEURE = date("H:i");
   $Subject = "Kindasitting - MDP";

//$madate_us =  "$annee"."-"."$mois"."-"."$jour";
   $mail_Data = "";
   $mail_Data .= "<html> \n";
   $mail_Data .= "<head> \n";
   $mail_Data .= "<title> Subject </title> \n";
   $mail_Data .= "</head> \n";
   $mail_Data .= "<body> \n";
 
     $mail_Data .= "Bonjour, <br> \n";
    $mail_Data .= "$message_out <br> \n";
   $mail_Data .= "$message2 <br> \n";
   $mail_Data .= "<br> \n";
   //$mail_Data .= "bla bla <font color=red> bla </font> bla <br> \n";
   $mail_Data .= "Bien cordialement<br> \n";
   $mail_Data .= "PAU Jazz <br> \n";
   $mail_Data .= "F.D. <br> \n";
 
   $mail_Data .= "<img src='http://Mysite/logo/logo_100.png'  /><br> ";

   $mail_Data .= "</body> \n";
   $mail_Data .= "</HTML> \n";

   $headers  = "MIME-Version: 1.0 \n";
   $headers .= "Content-type: text/html; charset= utf8\n";
   $headers .= "From: $from  \n";
   $headers .= "Disposition-Notification-To: $from  \n";

   // Message de Priorité haute
   // -------------------------
   $headers .= "X-Priority: 1  \n";
   $headers .= "X-MSMail-Priority: High \n";
   $CR_Mail = TRUE;
   $CR_Mail = @mail ($to, $Subject, $mail_Data, $headers);
   if ($CR_Mail === FALSE)
      {
      echo " Erreur envoi mail <br> \n";
      }
   else
      {
      echo " Mail envoyé <br> \n";
      }
?>
 

aeric

Expert
Licensed User
Longtime User
Here is an old code sample but I think you may get some ideas.


For latest PHP example, you can check:
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Sample:

B4X:
Wait For (SendEmailPHP("email@my,com","ewyetywete")) Complete (Result As String)

B4X:
Sub SendEmailPHP(mEMail As String, mPassword As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Dim Parameter() As String = Array As String ("MyEmail", mEMail, "MyPassword", mPassword)
    Try
        j.Initialize("", Me)
        j.Download2("https://MyDomain/SendEmail.php", Parameter)
        j.GetRequest.SetHeader("Content-Type","application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        Else
            Log(j.ErrorMessage)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return ResultURL
End Sub

Change PHP Scripts.

PHP:
$mail1 = $_GET["MyEmail"];
$mdp = $_GET["MyPassword"];

Result PHP in JSon:

   if ($CR_Mail === FALSE)
      {
      //echo " Erreur envoi mail <br> \n";
      echo '{"result": "False", "data" : ' . json_encode("Erreur envoi mail") . '}';
      }
   else
      {
      //echo " Mail envoyé <br> \n";
      echo '{"result": "True", "data" : ' . json_encode("Mail envoyé") . '}';
      }

See important:
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank you. I understand the code but the 2 samples don't run.. No modification in the bdd and no send mail. I'm going to verfy my code but is another library necessary as Phone ??
I use only OkHttpUtils2
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Please post your error message.
More precisely, If I enter an email address that does not exist in my database I have this message in the application: "" The email is not registered in our database. "
If I enter an address that exists in the database, nothing happens. No modification of the password in the database and no sending email to the address indicated, and no error message.
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
No, now it works. Sorry Aeric, I made a mistake in the name of a field in my table in the UPDATE request. Sorry and BRAVO again for this code.
 
Upvote 0
Top