473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Send mail to user if he forget the password

250 100+
I'm developing web site using php and my sql. In there i want to send a mail including new password to user, when he forget his password. How can i send mail using php? Could you please help me?
Jun 9 '08 #1
10 3183
r035198x
13,262 8TB
There is a built in mail() function that is easy to use. Look it up, try the code and post again if you still have problems.
Jun 9 '08 #2
ghjk
250 100+
There is a built in mail() function that is easy to use. Look it up, try the code and post again if you still have problems.

Yes. I tried it. But got an error saying "Access denied for user 'root'@'localhost' (using password: NO)". Is there any setting for server? This is my code
[PHP]
<?php
$err=0;

if(isset($_POST['forgot'])){
$send = $_POST['forgot'];

$sql = "SELECT Email FROM user_admin WHERE Email = '".$_POST["email"]."'";
$rs_email = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($rs_email) > 0){
$send = $_POST['forgot'];
$err=0;
}
else{
$send="";
$err=1;
}
}

if ($send == "forgot"){

$letters = array("A","B","C","D","E","F","G","H","I","J","K", "L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z","0 ","1","2",
"3","4","5","6","7","8","9","0");

$pass="";

$passlength=rand (8, 12);

for($i=0;$i<$passlength;$i++){
$pass.= $letters[rand (0, 35)];
}

$notencrypted=$pass;
$pass=md5($pass);

//echo $notencrypted;

$sql = "UPDATE user_admin SET Password ='".$pass."' WHERE Email = '".$_POST["email"]."'";


$body = "";
$body = $body."<p>Your password is : ".$notencrypted."</p>";

$subject = "Password Recovery";
$toemail = trim($_POST["my@gmail.com"]);

$headers = "From: Me <my@yahoo.com>\n";
$headers = $headers."Content-Type: text/html; charset=iso-8859-1\n"; // Mime type

mail($toemail, $subject, $body, $headers);

echo '<p>Your password has been changed and sent to your email address</p><br />';

}
else{
?>
<p>Please provide your email address and your password will be emailed to you</p><br />
<?php

if($err==1)
echo '<p style="color:#992928;">The email address that you were entered is not an existing one</p>';
?>
<form name="forgotpass" id="forgotpass" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validateforgot(this);">
<input name="email" id="email" type="text" size="25" /> <br />
<input name="forgot" value="forgot" id="forgot" src="images/submit.jpg" type="image" style="margin:5px 0 0 0;" />
</form>
<?php
}
?>
[/PHP]
Jun 10 '08 #3
ak1dnar
1,584 Expert 1GB
There is a permission problem or your user name/passwords are incorrect of your MySQL connection String. But how did you connect to your database? I can't see the lines of coding for that.
Jun 10 '08 #4
r035198x
13,262 8TB
There is a permission problem or your user name/passwords are incorrect of your MySQL connection String. But how did you connect to your database? I can't see the lines of coding for that.
Yep, if you call mysql_query() before mysql_connect(), PHP will use default values (specified in php.ini) to try and connect to the database. Those defaults are usually just a username with no password.
Jun 10 '08 #5
ghjk
250 100+
Yep, if you call mysql_query() before mysql_connect(), PHP will use default values (specified in php.ini) to try and connect to the database. Those defaults are usually just a username with no password.
Connect my sql using [PHP]include 'dbconnect.php';[/PHP] .
Jun 10 '08 #6
ghjk
250 100+
Can some one tell me how can i connect to remote mail server and test my code? Is there any way?
Jun 10 '08 #7
r035198x
13,262 8TB
Can some one tell me how can i connect to remote mail server and test my code? Is there any way?
Perhaps you are not understanding the problem here. That error message simply means that you are not getting access to your mysql database due to incorrect username/password. Try to solve that one first and see what happens.
Jun 10 '08 #8
ghjk
250 100+
Perhaps you are not understanding the problem here. That error message simply means that you are not getting access to your mysql database due to incorrect username/password. Try to solve that one first and see what happens.

Understood. I just try using
[PHP]<?php
$to = "my@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@yahoo";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>[/PHP]
This is working. I put this file to a server which has mail server. But i'm working on my local machine and is there any way to run that file on my machine with connecting mail server in another machine?
Jun 11 '08 #9
r035198x
13,262 8TB
Understood. I just try using
[PHP]<?php
$to = "my@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@yahoo";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>[/PHP]
This is working. I put this file to a server which has mail server. But i'm working on my local machine and is there any way to run that file on my machine with connecting mail server in another machine?
If the user can access the database from the database machine only then you need to grant them priviledges for remote access as well.
Jun 11 '08 #10
ghjk
250 100+
If the user can access the database from the database machine only then you need to grant them priviledges for remote access as well.

Still i'm confusing. The server which i hosted my web site doesn't have mail server. But There is another server which is having mail server. So i want to know how to connect that mail server using my website to send mail.
Jun 13 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
8
by: Katash | last post by:
Hello, I am new to PHP and am working on a login system for my site, currently supplied passwords are passed to MySQL and stored as md5 hashes, my question is :- seeing as md5 is 1 way only what...
11
by: fdu.xiaojf | last post by:
Hi, I just want to send a very simple email from within python. I think the standard module of smtpd in python can do this, but I haven't found documents about how to use it after googleing....
8
by: shapper | last post by:
Hello, I am trying to send an email using Asp.Net 2.0. I am getting the following error: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such...
4
Frinavale
by: Frinavale | last post by:
Introduction Many .NET applications will require an email be sent out for various reasons. This article will give a quick examples on how to send an email using VB.NET. The examples given can...
1
by: ghjk | last post by:
I want to send mail when user click "forgot password " button. This is my code and It doesn't send a mail. Could somebody tell me what is wrong with my code? require_once "Mail.php"; $from =...
1
by: selvamariappan | last post by:
Hi all, I have created a asp.net application (asp.net 2.0), in that i want to send a mail at the time of forget password for the users, how to send a password through mail. Thanks and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.