Page 1 of 1

php mail probs

Posted: Wed May 14, 2003 4:06 am
by irealms
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 (

Posted: Wed May 14, 2003 4:49 am
by volka
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

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>

thanks

Posted: Wed May 14, 2003 5:01 am
by irealms
mainly the problem is that it doesn't send mail, and puts some weird stuff in the address bar about the mail function, can't copy it atm as server is down (

k

Posted: Wed May 14, 2003 6:32 am
by irealms
tried your code and got the invalid request response

bar

Posted: Wed May 14, 2003 6:38 am
by irealms
when i do submit i am getting this

mailpass=&x=26&y=15

in the adress bar after index.php

when i send it takes me back to the logon section and the mail hasn't sent

Posted: Wed May 14, 2003 7:18 am
by volka
probably it didn't like method=post"

lol

Posted: Wed May 14, 2003 7:24 am
by irealms
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 :P

(

Posted: Wed May 14, 2003 7:43 am
by irealms
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

Posted: Wed May 14, 2003 7:55 am
by volka
"document contains no data" :(

woot

Posted: Wed May 14, 2003 8:02 am
by irealms
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 :cry:

Posted: Wed May 14, 2003 8:22 am
by volka
Iustitia fundamentum regnorum ;)

Posted: Wed May 14, 2003 8:28 am
by Gleeb
Just a quick not about your use of the from feild in that mail.
Anyone who has a half decent anti-spam system won't receive that mail as normal, as 'Crimson Marauders' is not a valid email address.

yup

Posted: Wed May 14, 2003 8:58 am
by irealms
i just did that for a test , worked fine sending to hotmail, going to set a domain email address up for the site and use that now :)