php mail probs
Moderator: General Moderators
php mail probs
i'm trying to make a script to mail the user their password if they lose it, at present i have:
<form method=post" action="index.php">
Enter your email:<br />
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" name=send value="send" style="font-size:10px;">
</form>
<?
if (isset($_POST['mailpass']))
{
$db_conn = mysql_connect("localhost", "cadmin", "cpass");
mysql_select_db("crimson", $db_conn);
$query = "select email from user where username='$valid_user'";
$result = mysql_query($query, $db_conn);
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = $_POST['mailpass'];
$from = "from: Crimson Maurauders \r\n";
$mesg = "You password is $password \r\n";
mail($email, $from, $mesg);
}
}
?>
it's not working atm (
<form method=post" action="index.php">
Enter your email:<br />
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" name=send value="send" style="font-size:10px;">
</form>
<?
if (isset($_POST['mailpass']))
{
$db_conn = mysql_connect("localhost", "cadmin", "cpass");
mysql_select_db("crimson", $db_conn);
$query = "select email from user where username='$valid_user'";
$result = mysql_query($query, $db_conn);
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = $_POST['mailpass'];
$from = "from: Crimson Maurauders \r\n";
$mesg = "You password is $password \r\n";
mail($email, $from, $mesg);
}
}
?>
it's not working atm (
right...
please note that your previous post does not contain a question.
Or a hint
Or a description
Or ..
anyway, try to put some output to your script so you can watch the progress and where and why it fails.
At least something like
please note that your previous post does not contain a question.
Or a hint
Or a description
Or ..
anyway, try to put some output to your script so you can watch the progress and where and why it fails.
At least something like
Code: Select all
<html>
<body>
<?php
if (isset($_POST['mailpass']))
{
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die('cannot connect to db-server');
mysql_select_db("crimson", $db_conn) or die('cannot select database');
echo "searching for '$valid_user'<br />";
$query = "select email from user where username='$valid_user'";
$result = mysql_query($query, $db_conn) or die('query failed');
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = $_POST['mailpass'];
$from = "from: Crimson Maurauders \r\n";
$mesg = "You password is $password \r\n";
echo '<fieldset><legend>will send</legend>', $email, '<br />', $from, '<br />', $mesg, '</fieldset>';
mail($email, $from, $mesg) or die('mail not sent');
echo 'done.';
}
else
echo 'record not found';
}
else
echo 'invalid request';
?>
</body>
</html>lol
hehe so times i'm soo thick, always miss the small errors, well it's going through rthe script now and i'm getting:
searching for ''
record not found
so something else for me to fix, lol
thanks again for the last bit of help
searching for ''
record not found
so something else for me to fix, lol
thanks again for the last bit of help
(
mail is not sending (
script is now
<form method="post" action="index.php?log=forgot">
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" value="send" style="font-size:10px";>
</form>
<?php
if (!$_POST['mailpass'])
{
echo "<div class=\"log\">please enter your email address.</div>";
}
elseif (isset($_POST['mailpass']))
{
$mailpass = $_POST['mailpass'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die('cannot connect to db-server');
mysql_select_db("crimson", $db_conn) or die('cannot select database');
echo "searching for '$valid_user'<br />";
$query = "select email from user where email='$mailpass'";
$result = mysql_query($query, $db_conn) or die('query failed');
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = mysql_result($result, 'email');
$from = "from: Crimson Maurauders \r\n";
$mesg = "your password is $password \r\n";
echo "<fieldset><legend>Mail sent to</legend> $email</fieldset>";
mail($email, $from, $mesg) or die('mail not sent');
echo 'done.';
}
else
echo 'record not found';
}
else
echo 'invalid request';
?>
adress is http://www.irealms.co.uk/crimson
click logon then forgot password link
script is now
<form method="post" action="index.php?log=forgot">
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" value="send" style="font-size:10px";>
</form>
<?php
if (!$_POST['mailpass'])
{
echo "<div class=\"log\">please enter your email address.</div>";
}
elseif (isset($_POST['mailpass']))
{
$mailpass = $_POST['mailpass'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die('cannot connect to db-server');
mysql_select_db("crimson", $db_conn) or die('cannot select database');
echo "searching for '$valid_user'<br />";
$query = "select email from user where email='$mailpass'";
$result = mysql_query($query, $db_conn) or die('query failed');
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = mysql_result($result, 'email');
$from = "from: Crimson Maurauders \r\n";
$mesg = "your password is $password \r\n";
echo "<fieldset><legend>Mail sent to</legend> $email</fieldset>";
mail($email, $from, $mesg) or die('mail not sent');
echo 'done.';
}
else
echo 'record not found';
}
else
echo 'invalid request';
?>
adress is http://www.irealms.co.uk/crimson
click logon then forgot password link
woot
to the relief of all concerned i have fixed it, hehe
new code is:
<form method="post" action="index.php?log=forgot">
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" value="send" style="font-size:10px";>
</form>
<?php
if (!$_POST['mailpass'])
{
echo "<div class=\"log\">please enter your email address.</div>";
}
elseif (isset($_POST['mailpass']))
{
$mailpass = $_POST['mailpass'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die('cannot connect to db-server');
mysql_select_db("crimson", $db_conn) or die('cannot select database');
//extract email address
$query = "select email from user where email='$mailpass'";
$result = mysql_query($query, $db_conn) or die('query failed');
//extract password
$query2 = "select passwd from user where email='$mailpass'";
$result2 = mysql_query($query2, $db_conn) or die('query failed');
$pass = mysql_result($result2, 'passwd');
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = mysql_result($result, 'email');
$from = "from: Crimson Maurauders \r\n";
$mesg = "your password is $pass \r\n";
echo "<fieldset><legend>Mail sent to</legend> $email</fieldset>";
mail($email, $from, $mesg) or die('mail not sent');
}
else
echo 'record not found';
}
else
echo 'invalid request';
?>
now all i have to do is get the registration bit done.
for the registration area i need it to send info to a database and then an admin can approve or deny before user can log on, might be back with questions on that, hehe. I'll give it a good go first.
hope you don't mind me asking noob questions on here, just started learning php and have a 5 month uni project coming up thats scary.
Have to make a web interface for a law firm to handle their day to day business
new code is:
<form method="post" action="index.php?log=forgot">
<input type="text" name="mailpass" style="style="font-size:10px;border:solid 1px;">
<input type=image src="buttons\send.gif" value="send" style="font-size:10px";>
</form>
<?php
if (!$_POST['mailpass'])
{
echo "<div class=\"log\">please enter your email address.</div>";
}
elseif (isset($_POST['mailpass']))
{
$mailpass = $_POST['mailpass'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die('cannot connect to db-server');
mysql_select_db("crimson", $db_conn) or die('cannot select database');
//extract email address
$query = "select email from user where email='$mailpass'";
$result = mysql_query($query, $db_conn) or die('query failed');
//extract password
$query2 = "select passwd from user where email='$mailpass'";
$result2 = mysql_query($query2, $db_conn) or die('query failed');
$pass = mysql_result($result2, 'passwd');
//mail user password
if (mysql_num_rows($result) >0 )
{
$email = mysql_result($result, 'email');
$from = "from: Crimson Maurauders \r\n";
$mesg = "your password is $pass \r\n";
echo "<fieldset><legend>Mail sent to</legend> $email</fieldset>";
mail($email, $from, $mesg) or die('mail not sent');
}
else
echo 'record not found';
}
else
echo 'invalid request';
?>
now all i have to do is get the registration bit done.
for the registration area i need it to send info to a database and then an admin can approve or deny before user can log on, might be back with questions on that, hehe. I'll give it a good go first.
hope you don't mind me asking noob questions on here, just started learning php and have a 5 month uni project coming up thats scary.
Have to make a web interface for a law firm to handle their day to day business