php mail probs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

php mail probs

Post 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 (
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

thanks

Post 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 (
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

k

Post by irealms »

tried your code and got the invalid request response
Last edited by irealms on Wed May 14, 2003 6:43 am, edited 1 time in total.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

bar

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

probably it didn't like method=post"
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

lol

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

(

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

"document contains no data" :(
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

woot

Post 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:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Iustitia fundamentum regnorum ;)
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post 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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

yup

Post 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 :)
Post Reply