stvchez Posted March 9, 2007 Share Posted March 9, 2007 I'm trying to email password results to users. They are getting the results mailed to them, so that is working, but are just receiving the username in both fields. here's my code and wonder where I am off.. $query = "SELECT username,password FROM tblNamesMain WHERE Email='$to'"; $result = mysql_query($query, $link); $username=mysql_result($result,"username"); $password=mysql_result($result,"password"); $body = "Here is your user Athletic Endurance account information that you requested.\n\nUsername: ".$username."\nPassword: " .$password." "; mysql_close($conn); if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); .... Quote Link to comment https://forums.phpfreaks.com/topic/42002-email-query-rset/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Probably better to do it this way: <?php $query = "SELECT username,password FROM tblNamesMain WHERE Email='$to'"; $result = mysql_query($query, $link) or DIE(mysql_error()); $uData = mysql_fetch_assoc($result); $username = $uData['username']; $password = $uData['password']; $body = "Here is your user Athletic Endurance account information that you requested.\n\nUsername: ".$username."\nPassword: " .$password." "; mysql_close($conn); if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42002-email-query-rset/#findComment-203664 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 The best way for both posts is to use the mail header's and then it the best way. Both read the mail function on php.net Quote Link to comment https://forums.phpfreaks.com/topic/42002-email-query-rset/#findComment-203671 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Mail headers are always good to include especially if you want to define reply-to etc. I simply posted a solution to the reason why the username and password were not showing up. But redarrow is right, for this to be done the best way possible, mail headers are a must. Some example headers for ya: <?php $mail_headers = "From: Your Mailer <[email protected]>\r\n"; $mail_headers .= "Reply-To: You at No Reply <[email protected]>\r\n"; $mail_headers .= "MIME-Version: 1.0\r\n"; $mail_headers .= "Content-type: text/plain; charset=utf-8\r\n"; $mail_headers .= "X-Mailer: Your Mailer"; mail($to, $subject, $body, $mail_headers, "-f" . "From: Your Mailer <[email protected]>\r\n"); ?> Anyhow hope the helps. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42002-email-query-rset/#findComment-203680 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.