
Quote from CDY@44 on January 7, 2021, 5:38 pmHello dear friends!
I would like to give the possibility to users of an application who have created an account and who have forgotten their password, to receive an email in their inbox containing a link to a page to create a new password. Easy to do?
Thanks to all of you!
Hello dear friends!
I would like to give the possibility to users of an application who have created an account and who have forgotten their password, to receive an email in their inbox containing a link to a page to create a new password. Easy to do?
Thanks to all of you!


Quote from luishp on January 7, 2021, 6:55 pm@cdy44-2 if you are using neoPhp Plugin for users management, keep in mind that passwords are stored hashed (encrypted).
Take a close look at neofunctions.php code to understand how it works. You should send username (or user id) and password to a new .php script and hash the password before updating the database row.//Get the username and password from the submited form $theUserName=$_POST['username'] $theUserPassword=$_POST['password'] //Hash the password $theUserPassword=password_hash($theUserPassword, PASSWORD_DEFAULT);Then open the database (procedure depends on your database) and execute this SQL:
UPDATE neousers SET password = '$theUserPassword' WHERE username='$theUserName';By checking the neofunctions.php code you will find how to open the database and execute the SQL query.
I hope it helpsRegards.
@cdy44-2 if you are using neoPhp Plugin for users management, keep in mind that passwords are stored hashed (encrypted).
Take a close look at neofunctions.php code to understand how it works. You should send username (or user id) and password to a new .php script and hash the password before updating the database row.
//Get the username and password from the submited form $theUserName=$_POST['username'] $theUserPassword=$_POST['password'] //Hash the password $theUserPassword=password_hash($theUserPassword, PASSWORD_DEFAULT);
Then open the database (procedure depends on your database) and execute this SQL:
UPDATE neousers SET password = '$theUserPassword' WHERE username='$theUserName';
By checking the neofunctions.php code you will find how to open the database and execute the SQL query.
I hope it helps
Regards.

Quote from luishp on January 7, 2021, 7:01 pm@cdy44-2 you can also try to hash the string using JavaScript before sending it to the server. This way it's not necessary to write a new .php script as you can use neoPhpExecSql as usual with the UPDATE SQL query:
UPDATE neousers SET password = ? WHERE username= ?;How to hash a string using Jasvascript:
https://www.geeksforgeeks.org/how-to-create-hash-from-string-in-javascript/Regards
@cdy44-2 you can also try to hash the string using JavaScript before sending it to the server. This way it's not necessary to write a new .php script as you can use neoPhpExecSql as usual with the UPDATE SQL query:
UPDATE neousers SET password = ? WHERE username= ?;
How to hash a string using Jasvascript:
https://www.geeksforgeeks.org/how-to-create-hash-from-string-in-javascript/
Regards

Quote from CDY@44 on January 7, 2021, 7:06 pmThank Luis for this answer.
The problem is that I dont know how I can send an email containing an URL link ( I think use the 'senddata.php' script like to send a form), but I don't see how to enclose the URL link in my form...
Best regards,
Thank Luis for this answer.
The problem is that I dont know how I can send an email containing an URL link ( I think use the 'senddata.php' script like to send a form), but I don't see how to enclose the URL link in my form...
Best regards,

Quote from luishp on January 7, 2021, 7:27 pm@cdy44-2 you should modify the script a little bit so it sends HTML instead of plain text:
<?php //Header required when app and php are of different origins header("Access-Control-Allow-Origin: *"); $message=""; if($_SERVER["REQUEST_METHOD"] === "POST"){ foreach($_POST as $key => $value){ $message .= "".htmlspecialchars($key).": ".htmlspecialchars($value)."\r\n"; } $to = "somebody@example.com"; $subject = "My subject"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com"; mail($to,$subject,$message,$headers); echo "EMAIL SUCCESSFULLY SEND"; }else{ $result = "INVALID DATA"; echo $result; } ?>The headers are the key.
Now you can send HTML in your email message:<a href="https://link.to/your/website">Click here to reset your password</a>I think this will work.
@cdy44-2 you should modify the script a little bit so it sends HTML instead of plain text:
<?php
//Header required when app and php are of different origins
header("Access-Control-Allow-Origin: *");
$message="";
if($_SERVER["REQUEST_METHOD"] === "POST"){
foreach($_POST as $key => $value){
$message .= "".htmlspecialchars($key).": ".htmlspecialchars($value)."\r\n";
}
$to = "somebody@example.com";
$subject = "My subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com";
mail($to,$subject,$message,$headers);
echo "EMAIL SUCCESSFULLY SEND";
}else{
$result = "INVALID DATA";
echo $result;
}
?>
The headers are the key.
Now you can send HTML in your email message:
<a href="https://link.to/your/website">Click here to reset your password</a>
I think this will work.

Quote from CDY@44 on January 7, 2021, 7:57 pmOk, but where put I the : <a href="https://link.to/your/website">Click here to reset your password</a> ?
Sorry to ask so basic questions...
Ok, but where put I the : <a href="https://link.to/your/website">Click here to reset your password</a> ?
Sorry to ask so basic questions...

Quote from CDY@44 on January 8, 2021, 12:40 amHi Luis,
I tried different places, no way to make it working...
I need your help. ;)Best regards,
Hi Luis,
I tried different places, no way to make it working...
I need your help. ;)
Best regards,

Quote from CDY@44 on January 8, 2021, 12:52 amOups ! I mean places to write : <a href="https://link.to/your/website">Click here to reset your password</a>
Oups ! I mean places to write : <a href="https://link.to/your/website">Click here to reset your password</a>

Quote from luishp on January 8, 2021, 2:47 pm@cdy44-2 To help you I need more information about what are you trying to achieve.
'senddata.php' script is designed to get information from a Form Object and send it to an email. So your HTML link should be sent from a Text Input or Text Area Object located inside a Form Object. But you can easily modify the script to send a predesigned content instead.Regards.
@cdy44-2 To help you I need more information about what are you trying to achieve.
'senddata.php' script is designed to get information from a Form Object and send it to an email. So your HTML link should be sent from a Text Input or Text Area Object located inside a Form Object. But you can easily modify the script to send a predesigned content instead.
Regards.


Quote from luishp on January 9, 2021, 9:02 am<?php //Header required when app and php are of different origins header("Access-Control-Allow-Origin: *"); $message="<a href='https://yourdomain.com/yourpath/'>Click here to reset your password</a>"; if($_SERVER["REQUEST_METHOD"] === "POST"){ $to = "somebody@example.com"; $subject = "My subject"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com"; mail($to,$subject,$message,$headers); echo "EMAIL SUCCESSFULLY SEND"; }else{ $result = "INVALID DATA"; echo $result; } ?>@cdy44-2 try this.
<?php
//Header required when app and php are of different origins
header("Access-Control-Allow-Origin: *");
$message="<a href='https://yourdomain.com/yourpath/'>Click here to reset your password</a>";
if($_SERVER["REQUEST_METHOD"] === "POST"){
$to = "somebody@example.com";
$subject = "My subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com";
mail($to,$subject,$message,$headers);
echo "EMAIL SUCCESSFULLY SEND";
}else{
$result = "INVALID DATA";
echo $result;
}
?>
@cdy44-2 try this.

Quote from CDY@44 on January 9, 2021, 2:45 pmHi @luishp,
I tried your sugestion but can't make it work...
<?php //Header required when app and php are of different origins header("Access-Control-Allow-Origin: *"); $message="<a href='https://yourdomain.com/yourpath/'>Click here to reset your password</a>"; if($_SERVER["REQUEST_METHOD"] === "POST"){ foreach($_POST as $key => $value){ $message .= "".htmlspecialchars($key).": ".htmlspecialchars($value)."\r\n"; } $to = $_POST['targetEmail']; $subject = "My subject"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com"; mail($to,$subject,$message,$headers); echo "EMAIL SUCCESSFULLY SEND"; }else{ $result = "INVALID DATA"; echo $result; } ?>
Hi @luishp,
I tried your sugestion but can't make it work...
<?php
//Header required when app and php are of different origins
header("Access-Control-Allow-Origin: *");
$message="<a href='https://yourdomain.com/yourpath/'>Click here to reset your password</a>";
if($_SERVER["REQUEST_METHOD"] === "POST"){
foreach($_POST as $key => $value){
$message .= "".htmlspecialchars($key).": ".htmlspecialchars($value)."\r\n";
}
$to = $_POST['targetEmail'];
$subject = "My subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com";
mail($to,$subject,$message,$headers);
echo "EMAIL SUCCESSFULLY SEND";
}else{
$result = "INVALID DATA";
echo $result;
}
?>
Uploaded files:

Quote from CDY@44 on January 9, 2021, 2:53 pmI have just changed the ligne " $to = "somebody@example.com";" by this "$to = $_POST['targetEmail'];"
By the way, I have just start to follow PHP formation...
I have just changed the ligne " $to = "somebody@example.com";" by this "$to = $_POST['targetEmail'];"
By the way, I have just start to follow PHP formation...

Quote from luishp on January 9, 2021, 4:41 pm@cdy44-2 I have added this code to the Form Object "success" tab:
ConsoleLog [data]...and I get a "EMAIL SUCCESSFULLY SENT" message on the web browser Console, but the email never comes.
Are you using webmaster@example.com as the sender email? You should only be allowed to send messages from an existing address at your own domain. Most web servers will reject any other email address.
@cdy44-2 I have added this code to the Form Object "success" tab:
ConsoleLog [data]
...and I get a "EMAIL SUCCESSFULLY SENT" message on the web browser Console, but the email never comes.
Are you using webmaster@example.com as the sender email? You should only be allowed to send messages from an existing address at your own domain. Most web servers will reject any other email address.

