Skip to main content
ElizabethGailLittle
Inspiring
February 6, 2021
Answered

Allow user to change password

  • February 6, 2021
  • 1 reply
  • 720 views

I have routines to register a new user who can update data files displayed on the website and to long them in to access update routines.  I now need to write a routine which allows a user to change his password.  I've asked for the email account and then sent a message to the account containing a link to an update routine, but the email is unauthenticated and contains a "noname" document containing the message, which is

Click on the link to reset your password. 

https://www.domain.com/reset.php

 

This is useless.  When I follow routines to reset a password, the link is never this legible - it's always long in indeciperable.  How do you do that?  And what am I doing wrong?

 

My code:

if (!$suspect && !$errors) {
// send email with link to reset routine
$to = $email;
$subject = 'Change password';
$headers = "Content-Type: text/plain, charset=utf-8\r\n";
$headers .= "From: webmaster@domain.com";
$param = '-fwebmaster@domain.com';
$message = "Click on link to change your password.\r\n\r\n".'https://www.support.domain.com/reset.php';
$mailSent = mail($to, $subject, $message, $headers,$param);
if (!$mailSent) {
$errors[] = "Your mail could not be sent.<br>";
} else {
echo 'Mail sent OK<br>';
}

This topic has been closed for replies.
Correct answer osgood_

It also might be because you are sending the email as plain text rather than html, which the link is, try the below:

 

 

 

if(!$suspect && !$errors) {
$to = $email;
$subject = "Change Password";
$from = "-fwebmaster@domain.com";
// build message
$message = "<h2>Click on link to change your password</h2>
<a href='https://www.support.domain.com/reset.php'>Reset</a>";
// set mime version for html headers
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-Type:text/html;charset=UTF-8"."\r\n";
$headers .= "From: $from\r\nReply-to: $email";
// send data
mail($to, $subject, $message, $headers, $from);
echo 'Mail sent OK';
}
else {
echo 'Your mail could not be sent.';
}

 

 

 

1 reply

ElizabethGailLittle
Inspiring
February 7, 2021

When I send the email, the email is going as a document containing the message and link.  How do I get it to send the content AS the email?  There's something I'm not seeing...

Legend
February 7, 2021

Must be something wrong with your server - the message comes through as an email if I test your code NOT as a document. Do you have another server to test on?

 

Its probably how you are passing the $email to the mail script? Test by hard-coding an email and see what happens:

 

$to = "blah@blah.com;

 

rather than:

 

$to = $email;