473,946 Members | 8,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send mail to user if he forget the password

250 Contributor
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 3220
r035198x
13,262 MVP
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 Contributor
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'@'localho st' (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($sq l) 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=ran d (8, 12);

for($i=0;$i<$pa sslength;$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.c om"]);

$headers = "From: Me <my@yahoo.com>\ n";
$headers = $headers."Conte nt-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:#9 92928;">The email address that you were entered is not an existing one</p>';
?>
<form name="forgotpas s" id="forgotpass " method="post" action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="retur n 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:5 px 0 0 0;" />
</form>
<?php
}
?>
[/PHP]
Jun 10 '08 #3
ak1dnar
1,584 Recognized Expert Top Contributor
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 MVP
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 Contributor
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 Contributor
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 MVP
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 Contributor
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.c om";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@yahoo";
$headers = "From: $from";
mail($to,$subje ct,$message,$he aders);
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 MVP
Understood. I just try using
[PHP]<?php
$to = "my@gmail.c om";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@yahoo";
$headers = "From: $from";
mail($to,$subje ct,$message,$he aders);
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

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

Similar topics

11
12111
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 use PHP to get inside an OWA (Microsoft Outlook Web Access) website to send email that way? The reason I ask is because my corporate office is going to do away with our rogue SMTP server access and force everything through Exchange
40
11954
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 following import win32com.client
3
3050
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 identifies itself as the computer name which is not in domain.com format, triggering spam filter problems). Instead, I want to have my code send through an SMTP server of a company that we pay for mail service. But they require a username and password....
8
3326
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 would be the best way to implement a 'Forgotten Password' system whereby the user supplies an e-mail address and the password is mailed to the user? The process does not require military level security but I would like to keep stored passwords...
11
22409
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. Are there any examples of using smtpd ? I'm not an expert,so I need some examples to learn how to use it. Or maybe there is a better way to to this?
8
7293
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 user here at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify,
4
17512
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 easily be translated into C#.NET. Storing Email Credentials If you are developing a web application the best place to store your email credentials is in your web.config file's <appSettings>. This will allow you to secure your email credentials using...
1
1481
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 = "test Sender <__MUNGED__>"; $to = "test Recipient <__MUNGED__>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?";
1
991
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 Regards , selvamariappan.c
0
10151
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11556
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11145
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10683
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8244
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6106
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3532
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.