adamjones Posted February 18, 2009 Share Posted February 18, 2009 I have this code, which should connect to my database, grab the e-mail for the username given, and mail them a message, which will have a link in for them to reset their password; <?php session_start(); require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $username = clean($_POST['username']); if($username == '') { $errmsg_arr[] = 'Invalid username'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login_failure.php"); exit(); } $qry="SELECT * FROM members WHERE username='$myusername'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['email'] = $member['email']; $_SESSION['subject'] = 'Password Request'; $_SESSION['message'] = 'Link to reset pass here'; $_SESSION['from'] = 'do.not.reply@email.com'; session_write_close(); } mail("$email", $subject, $message, $from); ?> <?php header("location: index.php"); exit(); ?> But I get this error; "Parse error: syntax error, unexpected $end in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 74" It should register the email, subject and message, and then send an email to them? Correct? Cheers, Adam. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted February 18, 2009 Share Posted February 18, 2009 which of those lines is 74? Quote Link to comment Share on other sites More sharing options...
mike12255 Posted February 18, 2009 Share Posted February 18, 2009 found it: <?php if($result) {//1 open if(mysql_num_rows($result) == 1) {//2open session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['email'] = $member['email']; $_SESSION['subject'] = 'Password Request'; $_SESSION['message'] = 'Link to reset pass here'; $_SESSION['from'] = 'do.not.reply@email.com'; session_write_close(); }//1 close were is 2 close?? mail("$email", $subject, $message, $from);?> look at your braces '}' in the code i posted i put comments next to them Quote Link to comment Share on other sites More sharing options...
adamjones Posted February 18, 2009 Author Share Posted February 18, 2009 found it: <?php if($result) {//1 open if(mysql_num_rows($result) == 1) {//2open session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['email'] = $member['email']; $_SESSION['subject'] = 'Password Request'; $_SESSION['message'] = 'Link to reset pass here'; $_SESSION['from'] = 'do.not.reply@email.com'; session_write_close(); }//1 close were is 2 close?? mail("$email", $subject, $message, $from);?> look at your braces '}' in the code i posted i put comments next to them Ok, thanks That fixed it, however, it's not sending the message for some reason? Quote Link to comment Share on other sites More sharing options...
mike12255 Posted February 18, 2009 Share Posted February 18, 2009 are you getting an error?if not add this at the top of the page : ini_set('error_reporting', E_ALL); P.s why do you have $email inside quotes " " ? if you dont get an error message after adding that then im not to sure. Quote Link to comment Share on other sites More sharing options...
adamjones Posted February 18, 2009 Author Share Posted February 18, 2009 are you getting an error?if not add this at the top of the page : ini_set('error_reporting', E_ALL); P.s why do you have $email inside quotes " " ? if you dont get an error message after adding that then im not to sure. are you getting an error?if not add this at the top of the page : ini_set('error_reporting', E_ALL); P.s why do you have $email inside quotes " " ? if you dont get an error message after adding that then im not to sure. Because the format for it should be; mail("name@domain.com", $subject, $message, $from); So, I grabbed the email from the database of the user, set it to register as a variable, and placed it in there. Oh dear... These are the errors; "Notice: Undefined variable: email in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56 Notice: Undefined variable: subject in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56 Notice: Undefined variable: message in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56 Notice: Undefined variable: from in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56" I have defined them though, right? Quote Link to comment Share on other sites More sharing options...
trq Posted February 18, 2009 Share Posted February 18, 2009 I have defined them though, right? No. Seems you should be using.... mail($_SESSION['email'], $_SESSION['subject'], $_SESSION['message'], $_SESSION['from']); Quote Link to comment Share on other sites More sharing options...
adamjones Posted February 18, 2009 Author Share Posted February 18, 2009 I have defined them though, right? No. Seems you should be using.... mail($_SESSION['email'], $_SESSION['subject'], $_SESSION['message'], $_SESSION['from']); Ahh. Thank you very much! All working now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.